Skip to content

How to run services using Systemd

Cosmo edited this page Nov 14, 2022 · 6 revisions

In this tutorial I want to show you how easy is to start a service installed inside JuNest via systemd/User. The main advantages on executing a service inside JuNest via systemd are:

  • The service will keep running even when the JuNest is terminated since the service JuNest session will be handled by systemd service itself;
  • The service can be started as soon as the user will log in;
  • The systemd/Timers can be used

One limitation of this approach is that the host OS must use systemd as process manager. Most distributions are now moving to systemd such as Debian, Fedora, ArchLinux.

In this tutorial I am going to install dropbox as a systemd service. The systemd version used is 226.

Remember: Every interaction with systemd must be done via the user mode and not fakeroot mode. This is because the systemd communicates with DBUS which is setup only when the normal user is logged in.

Access as fakeroot and install the needed packages:

JUNEST_HOME=~/.junest-dropbox junest -f
pacman -Sy nano base-devel systemd mesa-libgl gtk2
yay -S dropbox

As either normal user or fakeroot, create the unit service for dropbox. If you want Dropbox to appear in your system tray, you will need to edit the service unit so that it knows which X display the system tray is in:

nano ~/.config/systemd/user/dropbox.service
-----------
[Unit]
Description=Dropbox

[Service]
Environment=DISPLAY=:0 JUNEST_HOME=/home/myuser/.junest-dropbox
Type=simple
ExecStart=/home/myuser/junest/bin/junest -- /usr/bin/dropbox
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure

[Install]
WantedBy=default.target

Where /home/myuser is your home directory.

To start the service:

systemctl --user start dropbox

To have Dropbox automatically start when you log in, simply enable the user service:

systemctl --user enable dropbox
Created symlink from ~/.config/systemd/user/default.target.wants/dropbox.service to ~/.config/systemd/user/dropbox.service.