Skip to content

Running as a service

Hugo Osvaldo Barrera edited this page Jun 17, 2021 · 10 revisions

Using systemd

Many distributions use systemd to manage both system services an user services. librespot can be run as a service using systemd.

Running as a system-wide service

contrib/systemd.service should be installed into /usr/lib/systemd/system/. This'll allow running librespot as a system-wide service permanently by enabling it:

systemctl enable --now librespot

This is the recommended approach for embedded devices. Note that only root can manage this service.

It is recommended that downstream packagers include this file in distribution packages.

Running as a user service

Note: This is pending merging of https://github.com/librespot-org/librespot/pull/800

contrib/systemd.user.service should be installed into /usr/lib/systemd/user/. This'll allow running librespot as a user service which can be controlled without privileges, and is bound to the currently logged in user.

systemctl --user enable --now librespot

This is the recommended approach for desktops and especially for shared devices where not all users will have root privileges.

It is recommended that downstream packagers include this file in distribution packages.

Using supervisord

Warning! Experimental

Running librespot in the background and on boot can be done rather easily if using linux using Supervisor.

You may need to edit these slightly for other distributions.

For Ubuntu/Debian:

Install supervisor using apt.

sudo apt update
sudo apt install supervisor

Create the supervisor configuration file.

sudo nano /etc/supervisor/conf.d/librespot.conf

In there paste the following (edit the options as required):

[program:librespot]
command = /path/to/librespot --name "Speaker"
redirect_stderr = true
stdout_logfile = /var/log/librespot.log

Finally run the following to restart supervisor.

sudo supervisorctl update

If you are having problems have a look at the log file. To restart after changing config:

sudo supervisorctl reread
sudo supervisorctl restart librespot

and to check the status:

sudo supervisorctl status

For a full list of supervisor options see here.

When using the PulseAudio backend

In case you would like to use the pulseaudio backend, you will need to specify the XDG_RUNTIME_DIR environment variable for librespot to connect to the pulseaudio server. For example, add the following line to /etc/supervisor/conf.d/librespot.conf:

environment=XDG_RUNTIME_DIR="/run/user/1000"

You might have to edit 1000 to the id of your user.

Clone this wiki locally