3

I tried to start at boot a service running in my user's context, which did not work with multi-user as target but only with default, i.e., graphical.

I enabled lingering for my user and the service

sudo loginctl enable-linger $USER
systemctl --user enable $SERVCE
systemctl --user start $SERVICE

However, the service did not got started after reboots.

The service originally targeted multi-user

[Install]
WantedBy=multi-user.target

i.e., resulting in the service link

$HOME/.config/systemd/user/multi-user.target.wants/SERVICE.service

Not as expected, the service did not got started at boot.

Only after changing the target to default

WantedBy=default.target

(which is currently graphical) and re-enabling the service, the service got started automatically.

However, I had assumed that graphical is downstream of multi-user as target, i.e., being 'later', or?

What may be have prevented the service to start with multi-user?

THX
  • 317
  • 4
  • 12

1 Answers1

5

From man 7 systemd.special,

SPECIAL USER UNITS.

  When systemd runs as a user instance, the following special units are
  available, which have similar definitions as their system counterparts:

  default.target, shutdown.target, sockets.target, timers.target,
  paths.target, bluetooth.target, printer.target, smartcard.target,
  sound.target.

So there is no user multi-user.target.

meuh
  • 51,383
  • ah, thanks! I had implicitly assumed, that the states for users are the equivalent to the system! Good to know about it - as potential pitfall! – THX Jul 25 '16 at 07:46
  • Would you suggest to use default.target for WantedBy= in .service , and timers.target in timer ? as in https://niels.kobschaetzki.net/blog/2015/11/11/creating-systemd-timers-instead-of-a-personal-crontab/ – Grzegorz Wierzowiecki Jul 31 '16 at 15:42
  • @GrzegorzWierzowiecki I dont think the .service has a WantedBy=, as it will always be called explicitly from the timer unit. But the examples I have put a Wants=....timer in the [Unit] part of the .service. – meuh Jul 31 '16 at 15:51
  • Btw. Why do I see multi-user.target in pastebin.com/8B5jLUkz output of systemd-analyze critical-chain ? (I am using Arch Linux -> maybe it's distro specific?) – Grzegorz Wierzowiecki Jul 31 '16 at 15:52