Manual starting of services (or using openrc)


#1

Hi,

I had a look at Funkwhale and it looks very nice, thanks for the good work! I decided I would like to start using it at home. For this, I installed using the instructions here, which are fine. However, I am not using systemd, so I would like another way to start the service, beat, and worker.

So, my options would be either:
a) start the various services needed manually and write a script for that, or
b) use an openrc script ( or write one as soon as I got my manual script to work).

The celery parts i can start using:
/srv/funkwhale/virtualenv/bin/celery -A funkwhale_api.taskapp beat -l INFO
/srv/funkwhale/virtualenv/bin/celery -A funkwhale_api.taskapp worker -l INFO

I mainly have trouble running the Daphne part:

/srv/funkwhale/virtualenv/bin/daphne -b 127.0.0.1 -p 5000 config.asgi:application --proxy-headers &

This wont start and creates Django warnings:
django.core.exceptions.ImproperlyConfigured: Requested setting LOGGING_CONFIG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

I wouldn’t know where to start so just pointing to some manual startup-commands would already help. However, I cant find any documentation on this. Can someone point me to the right direction?

Thanks for any pointers,

Alexander.

Ps: Or maybe there already is an init script for openrc?


#2

Hi @alexander! It’s exciting to see you deploy the project on non-systemd platform!

I suspect the missing bit in your case is that you don’t source the .env file before running the exec command, which means Funkwhale miss the required configuration to start.

In our systemd scripts, we have this:

WorkingDirectory=/srv/funkwhale/api
EnvironmentFile=/srv/funkwhale/config/.env

Especially, the EnvironmentFile thing is a systemd instruction that loads the env vars from the specified before running the command.

We don’t have openrc scripts yet, but we have FreeBSD Init V scripts that were contributed a while ago, maybe those will be helpful for you?


#3

Hi @eliotberriot,

Thanks for your reply. Indeed it seems to have to do with the env variables.

I now use the following script (start.sh) which seems to work and contains an explicit declaration for the DJANGO_Setting variable since that seemed to be missing.
Note that I run it from /srv/funkwhale/api at the moment. This script seems to start the processes, so that looks good!

#!/bin/bash
source /srv/funkwhale/virtualenv/bin/activate
pip --version
python --version

export DJANGO_SETTINGS_MODULE=config.settings.production
/srv/funkwhale/virtualenv/bin/celery -A funkwhale_api.taskapp beat -l INFO --workdir /srv/funkwhale/api  &
/srv/funkwhale/virtualenv/bin/celery -A funkwhale_api.taskapp worker -l INFO --workdir /srv/funkwhale/api  &
/srv/funkwhale/virtualenv/bin/daphne -b 127.0.0.1 -p 5000 config.asgi:application --proxy-headers

My next challenge is to get nginx or apache to display something from Funkwhale, since right now I cant get that to work. Somehow, I think nginx ( or apache) point to the right file but don’t actually activate any active content from the front- directory ( I.e. if I add a remark to the index.html, then that is displayed, but nothing more).

Thanks so far anyhow,

Alexander.


#4

Hi. I’m running Funkwhale on a non-docker instance without Systemd as well. I made a quite dirty work-around with Supervisor instead of writing an OpenRC script. That’s far from perfect, given that there is no kind of process group (a parent process for both server, celery and beat), and also Supervisor doesn’t handle env files. So I’d be interested in an OpenRC instead, and I can help test setups.


#5

Hi @gordon, good to know.

I think I almost have a mostly working (simple) init-script.
However, I still have trouble getting the end-to-end service running which I think has to do with nginx, but it might also be that the service is not actually running as expected.

Can you maybe share you nginx configuration? (and then not only the site-enabled’ config, but also the nginx.conf that refers to ’ sites-enabled’) so I can see if i can get the frontend to work. Right now it does serve the right index.html, but stays blank.

Thanks!

Alexander.


#6

@eliotberriot, @gordon,

Thanks for helping me out.
Down here you find my initial openrc initscript for starting/stopping funkwhale on my gentoo server. I realise it is not a state-of-the art initscript, but it works for me for now.
I will try to format it in a more ‘formal’ openrc way later, including moving the configuration parameters to a separate /etc/conf.d file, as it is supposed to be :wink:

Some remarks on using this script:

  • it starts redis, postgresql, and nginx. This also means that if you f.e. use apache, you need to adapt the script
  • It assumes funkwhale is installed , and able to run, per the (debian/source) instructions.
  • the stopping works, unless something crashes. I had some trouble restarting at some point when redit wouldnt close done correctly ( a reboot did help, but that is not ideal of course)

Initial attempt at working init file:

/etc/init.d/funkwhale

#!/sbin/openrc-run
NAME=funkwhale
PIDFILE=/var/run/$NAME.pid
USER=funkwhale
DAEMON_ARGS="-b 127.0.0.1 -p 5000 config.asgi:application --proxy-headers "
EXECDAPHNE=/srv/funkwhale/virtualenv/bin/daphne
WORKDIR=/srv/funkwhale/api

depend() {
        need net redis postgresql nginx
}

start() {
        ebegin "Starting Funkwhale components"
        cd /srv/funkwhale/api
        set -a && source /srv/funkwhale/config/.env && set +a
        echo 'Starting Beat and Worker'
        /srv/funkwhale/virtualenv/bin/celery -A funkwhale_api.taskapp beat -l INFO --workdir $WORKDIR >> /var/log/funk/beat.log 2>&1&
        /srv/funkwhale/virtualenv/bin/celery -A funkwhale_api.taskapp worker -l INFO --workdir $WORKDIR >>  /var/log/funk/worker.log 2>&1&
        sleep 1
        #  export DJANGO_SETTINGS_MODULE=config.settings.production
        echo 'Starting Daphne '
        start-stop-daemon --start --user $USER --make-pidfile --pidfile $PIDFILE  -d $WORKDIR  --exec $EXECDAPHNE -- $DAEMON_ARGS >> /var/log/funk/daphne.log 2>&1&
        # start-stop-daemon --start  --quiet  --user $FUNK_USER --make-pidfile  --pidfile $PIDFILE --background  --exec $DAEMON -- $DAEMON_ARGS
        eend $?
}

stop() {
        ebegin "Stopping Funkwhale"
        start-stop-daemon --stop --pidfile $PIDFILE
        #killall -9 celery >/dev/null
        #killall -9 daphne >/dev/null
        eend $?
}

Please provide any feedback, testing etc, so I can adapt the file.
My next step would be to create a proper ebuild to ensure installation in an easy way.

Alexander.


#7

To follow up on this, I now created three init-files for Openrc, one for each task, in line with the three systemd .service files and the three bsd/sysvinit files in the ‘deploy’ directory for beat, worker, and server.

Best,

Alexander