1
0
mirror of https://github.com/etesync/server synced 2024-11-22 00:38:07 +00:00
5 Run uvicorn at boot
Pierre-Alain TORET edited this page 2024-04-24 19:54:26 +02:00

Having to run uvicorn manually is annoying and not maintainable.
Instead, you should have the system automatically start it at boot for you.

Linux

systemd

We can have systemd handle lauching uvicorn by creating a unit file for it. Create a new file called etebase_server.service and paste in the following. Don't forget to set the correct path to your installation and to your venv, as well as the correct user and group.

[Unit]
Description=Execute the etebase server.

[Service]
WorkingDirectory=/path/to/etebase
ExecStart=/path/to/etebase/.venv/bin/uvicorn etebase_server.asgi:application --uds /tmp/etebase_server.sock

[Install]
WantedBy=multi-user.target

Note that we directly run the uvicorn which is located in our virtual environment (at /path/to/etebase/.venv). If your virtual environment is located elsewhere, be sure to update this.

Next, copy this to /etc/systemd/system/. systemd should now be able to start it. By also enabling it, it will launch at boot.

$ sudo cp etebase_server.service /etc/systemd/system
$ sudo systemctl start etebase_server
$ sudo systemctl enable etebase_server

Check to see if it worked! If it didn't work, use the command sudo systemctl status etebase_server to see what went wrong.

FreeBSD

rc script

Create a rc script in /usr/local/etc/rc.d/etesync as it's not part of the base system.

#!/bin/sh
#
# PROVIDE: etesync
# REQUIRE: NETWORKING LOGIN postgresql
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable etesync:
#
#etesync_enable="YES"

. /etc/rc.subr

name="etesync"
rcvar="etesync_enable"

load_rc_config $name

: ${etesync_enable="NO"}

pidfile="/var/run/etesync/etesync.pid"
procname="/usr/local/share/etesync/venv/bin/uvicorn"
command="/usr/sbin/daemon"
command_interpreter="/usr/local/share/etesync/venv/bin/python3.9"
command_args="-f -u www -o /var/log/etesync.log -p ${pidfile} /usr/local/share/etesync/venv/bin/uvicorn etebase_server.asgi:application --uds /var/run/etesync/etesync.socket --env-file /usr/local/etc/etesync/etesync_env --app-dir /usr/local/share/etesync"

run_rc_command "$1"

Then place your installation in /usr/local/share/etesync and the venv itself in /usr/local/share/etesync/venv

In /usr/local/etc/etesync/etesync_env, place the following :

ETEBASE_EASY_CONFIG_PATH=/usr/local/etc/etesync/etesync.ini

In /usr/local/etc/etesync/etesync.ini place your configuration as explained in other wiki sections.

Then you just have to add etesync_enable="YES" in /etc/rc.conf or run `rc_enable