update and publish old draft about LibreTranslate installation
This commit is contained in:
parent
4aefef8e1e
commit
ac43a71575
1 changed files with 125 additions and 41 deletions
|
@ -1,69 +1,153 @@
|
||||||
---
|
---
|
||||||
title: 73 install libretranslate
|
title: Install LibreTranslate on a VM
|
||||||
summary: >
|
summary: >
|
||||||
Summarized how I finally got LibreTranslate installed on my local mastodon
|
Summarized how I finally got LibreTranslate installed on my Archlinux based
|
||||||
test-instance. <small>I am not affiliated with LibreTranslate -- this post reflects
|
local mastodon test-instance.
|
||||||
|
<small>I am not affiliated with LibreTranslate -- this post reflects
|
||||||
my own use case. The thumbnail is a trademark of
|
my own use case. The thumbnail is a trademark of
|
||||||
[LibreTranslate](https://github.com/LibreTranslate/LibreTranslate/blob/main/TRADEMARK.md).</small>
|
[LibreTranslate](https://github.com/LibreTranslate/LibreTranslate/blob/main/TRADEMARK.md).</small>
|
||||||
date: 2024-12-07T07:22:28+01:00
|
date: 2024-12-07T07:22:28+01:00
|
||||||
lastmod: 2024-12-08T11:14:36+0000
|
lastmod: 2024-12-08T12:40:21+0000
|
||||||
categories:
|
categories:
|
||||||
- amateur-radio
|
|
||||||
- computerstuff
|
- computerstuff
|
||||||
tags:
|
tags:
|
||||||
- draft_post
|
- Archlinux
|
||||||
|
- command-line
|
||||||
# showBreadcrumbs: true
|
- Linux
|
||||||
# showDate: false
|
- Mastodon
|
||||||
# showReadingTime: false
|
- selfhost
|
||||||
# showWordCount: false
|
- server
|
||||||
# showPagination: false
|
- Unraid
|
||||||
|
|
||||||
# feed_exclude: true
|
|
||||||
# site_exclude: true
|
|
||||||
|
|
||||||
# some help
|
|
||||||
#
|
|
||||||
# highlighting with highlights
|
|
||||||
#
|
|
||||||
# use table, as inline creates a padding around
|
|
||||||
# and it pushes the text more to the right side (end of screen)
|
|
||||||
#
|
|
||||||
# ~~~html {linenos=table,hl_lines="3-6"}
|
|
||||||
# ~~~html {linenos=inline,hl_lines="1,3-6"}
|
|
||||||
|
|
||||||
draft: true
|
|
||||||
---
|
---
|
||||||
|
|
||||||
upgraded VM to 4 cores and 8GB RAM
|
I usually run the mastodon instance on a <abbr title="virtual machine">VM</abbr>
|
||||||
|
with two cores and 4GB of RAM. That is plenty of power for the simple tasks a
|
||||||
|
single-user instance has to do.
|
||||||
|
|
||||||
(also had to increase /tmp folder for pip installation of libretranslate:
|
## Preface / preparations
|
||||||
|
|
||||||
|
But for the installation of LibreTranslate I enhanced (after powering off the VM)
|
||||||
|
the cores to 4 and the RAM to 8GB.
|
||||||
|
|
||||||
|
While installing the needed python packages I ran out of space on the <kbd>/tmp</kbd>
|
||||||
|
filesystem (which was just a <kbd>tmpfs</kbd> filesystem). We could increase the
|
||||||
|
RAM to 10GB or 12GB but for me it worked by only using 8GB of RAM for this VM.
|
||||||
|
|
||||||
|
### Modify <kbd>/etc/fstab</kbd> and increase <kbd>/tmp</kbd>
|
||||||
|
|
||||||
|
To increase <kbd>/tmp</kbd> we log into the VM and modify the file <kbd>/etc/fstab</kbd>.
|
||||||
|
|
||||||
|
```fstab
|
||||||
tmpfs /tmp tmpfs size=6G,nr_inodes=10k 0 0)
|
tmpfs /tmp tmpfs size=6G,nr_inodes=10k 0 0)
|
||||||
|
```
|
||||||
|
|
||||||
sudo useradd --create-home --home-dir /var/lib/libretranslate libretranslate
|
### Install some needed packages
|
||||||
|
|
||||||
paru -S python-libretranslate-git cmake
|
I had much prepared/installed already, but `cmake` was still missing.
|
||||||
|
|
||||||
sudo su - libretranslate
|
```console
|
||||||
|
$ paru -S cmake
|
||||||
|
```
|
||||||
|
|
||||||
python -m venv venv
|
## The installation of LibreTranslate
|
||||||
|
|
||||||
source venv/bin/activate
|
### Create a dedicated user for the service
|
||||||
|
|
||||||
pip3 install --prefer-binary libretranslate
|
```console
|
||||||
|
$ sudo useradd --create-home --home-dir /var/lib/libretranslate libretranslate
|
||||||
|
```
|
||||||
|
|
||||||
argospm update
|
Change to the new user:
|
||||||
|
|
||||||
for lang in $(argospm search | grep -E "^translate-.._en.*"| awk '{ print $2 }' | xargs); do echo argospm install translate-${lang}\_en; done
|
```console
|
||||||
|
$ sudo su - libretranslate
|
||||||
|
$ python -m venv venv
|
||||||
|
$ source venv/bin/activate
|
||||||
|
$ pip install --prefer-binary libretranslate
|
||||||
|
$ argospm update
|
||||||
|
```
|
||||||
|
|
||||||
(remove echo from command to finally execute; the command shows a list of install commands)
|
### Install every language possible
|
||||||
|
|
||||||
now edit mastodon conf to use libretranslate
|
```console
|
||||||
|
$ for lang in $(argospm search | cut -d: -f1 ); do echo argospm install $lang;done
|
||||||
|
```
|
||||||
|
|
||||||
cd /var/lib/mastodon
|
Remove `echo` from that command to actually install them (the command above prints the commands
|
||||||
|
needed to install the languages; you can only install one at a time).
|
||||||
|
|
||||||
add to .env.production
|
#### If you only want to translate to English, use this instead
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ for lang in $(argospm search | grep -E "^translate-.._en.*"| awk '{ print $2 }' | xargs); do echo argospm install translate-${lang}_en; done
|
||||||
|
```
|
||||||
|
|
||||||
|
Also remove `echo` to actually install these translation packages.
|
||||||
|
|
||||||
|
### Let mastodon know of the LibreTranslate installation
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ cd /var/lib/mastodon
|
||||||
|
```
|
||||||
|
|
||||||
|
Add to .env.production:
|
||||||
|
|
||||||
|
```env
|
||||||
ALLOWED_PRIVATE_ADDRESSES=127.0.0.1
|
ALLOWED_PRIVATE_ADDRESSES=127.0.0.1
|
||||||
LIBRE_TRANSLATE_ENDPOINT=http://127.0.0.1:5000
|
LIBRE_TRANSLATE_ENDPOINT=http://127.0.0.1:5000
|
||||||
|
```
|
||||||
|
|
||||||
|
### Create a systemd unit file to automatically start LibreTranslate
|
||||||
|
|
||||||
|
File: <kbd>/etc/systemd/system/libretranslate.service</kbd>
|
||||||
|
|
||||||
|
```systemd
|
||||||
|
[Unit]
|
||||||
|
Description=LibreTranslate
|
||||||
|
After=network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
User=libretranslate
|
||||||
|
Group=libretranslate
|
||||||
|
WorkingDirectory=/var/lib/libretranslate/
|
||||||
|
ExecStart=/var/lib/libretranslate/venv/bin/python /var/lib/libretranslate/venv/bin/libretranslate --host 0.0.0.0 --port 5000 --suggestions --req-limit 20 --update-models
|
||||||
|
Restart=always
|
||||||
|
#CPUQuota=50%
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
```
|
||||||
|
|
||||||
|
### Start LibreTranslate
|
||||||
|
|
||||||
|
First, tell systemd of the new unit file:
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ sudo systemctl daemon-reload
|
||||||
|
```
|
||||||
|
|
||||||
|
Enable and start the service:
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ sudo systemctl enable --now libretranslate.service
|
||||||
|
```
|
||||||
|
|
||||||
|
## Restart Mastodon to let it know of the translation service
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ sudo systemctl restart mastodon-web.service
|
||||||
|
```
|
||||||
|
|
||||||
|
## Remove the extra space from <kbd>/tmp</kbd>
|
||||||
|
|
||||||
|
Comment or remove the line in <kbd>/etc/fstab</kbd>
|
||||||
|
|
||||||
|
```fstab
|
||||||
|
#tmpfs /tmp tmpfs size=6G,nr_inodes=10k 0 0)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Reduce the VMs specs back to normal
|
||||||
|
|
||||||
|
I set the VM back to two cores and 4GB of RAM. Poweroff the VM
|
||||||
|
with `sudo poweroff` or `sudo systemctl poweroff` and change the values
|
||||||
|
back to normal. Start the VM again and all services should come online.
|
||||||
|
|
Loading…
Reference in a new issue