11

OS: Ubuntu 20.04.3

$ \cat /home/nikhil/.config/systemd/user/Festival.service
[Unit]
Description=Festival Service

[Service] ExecStart=/usr/bin/festival --server Restart=on-failure RestartSec=10 SyslogIdentifier=FestivalService

[Install] WantedBy=multi-user.target

Description

I did systemctl --user enable Festival.service, rebooted my system. But the festival server does not start. Only when I do manually systemctl --user start Festival.service, it starts.

Issue

Could you please tell me, why user service does not work with multi-user.target, which is suppose to work on every boot?

Reference

Porcupine
  • 1,892
  • What was the output of systemctl --user enable Festival.service? It should tell you something about the symlinks created. – TNW Aug 27 '21 at 13:11
  • @TNW Created symlink /home/nikhil/.config/systemd/user/multi-user.target.wants/Festival.service → /home/nikhil/.config/systemd/user/Festival.service. – Porcupine Aug 27 '21 at 18:21

1 Answers1

12

multi-user.target is appropriate for the system-bus, but you are using --user which works with the user-bus. The user-bus does not typically have multi-user.target

stew ~ $ sudo systemctl status multi-user.target
● multi-user.target - Multi-User System
     Loaded: loaded (/lib/systemd/system/multi-user.target; static)
     Active: active since Fri 2021-08-27 10:09:41 CEST; 5h 19min ago
       Docs: man:systemd.special(7)

Aug 27 10:09:41 stewbian systemd[1]: Reached target Multi-User System.

stew ~ $ systemctl --user status multi-user.target Unit multi-user.target could not be found.

The solution is to either use the system bus (which will start the service on boot), or use the user bus (which will start when the user logs in).

If you choose to stick with the user bus then change multi-user.target to default.target (which is the main user target).

If you choose to switch to the system bus, then you can still run the service as your user with User= in the [Service] section.

See man systemd.special for info about these targets.

Stewart
  • 13,677
  • Thanks I will accept after testing it. Also, if we are trying to start an application that requires GUI such as Firefox from user service, can we use default.target? – Porcupine Aug 27 '21 at 18:28
  • 1
    For a GUI app, the user-bus is certainly the way to go. graphical-session.target or xdg-desktop-autostart.target are the design for starting GUI applications, but in reality these are not implemented by all desktop environments yet. Try these first for firefox. If these are not implemented on your machine, then default.target is your answer (though this may also run if you login via ssh) – Stewart Aug 28 '21 at 07:04
  • Some people may suggest graphical.target on the system bus, but the problem with this is you need to manually set the $DISPLAY and $XAUTHORITY environment variables in your service, you need to set User= and it will try to start when reaching the display manager login screen instead of when the desktop environment is started. – Stewart Aug 28 '21 at 07:08
  • I enabled using graphical-seesion.target. I see that this got created /home/nikhil/.config/systemd/user/graphical-session.target.wants/Browser.service. Also, I saw that the folder /usr/lib/systemd/user/graphical-session.target.wants exists. So, graphical-session.target.wants can exists in 2 locations, right? – Porcupine Aug 28 '21 at 12:48
  • When enabling a unit, systemd creates a symbolic link in *.wants/ to your unit. When starting graphical-session.target, systemd check graphical-session.target.wants/ to set the Wants= relationship. Then raises any units with a link in that directory. – Stewart Aug 29 '21 at 07:04