9

I have a system service that is executed for selected users. Name is serv@<uid> (<uid> is UID of the user). I want to share user's resource limits with the service (place it into user-<uid>.slice) and I also want to use his permissions.

/etc/systemd/system/[email protected]

[Unit]
Description=My service for user %i

[Service]
Type=simple
ExecStart=/usr/local/bin/serv.sh
Restart=always
User=%i
Slice=user-%i.slice
SuccessExitStatus=0 255 SIGKILL SIGTERM

[Install]
WantedBy=multi-user.target

When the user logs out, the service is terminated using SIGTERM. Why isn't the service restarted? How can I set it up so the service will not be terminated?

jiwopene
  • 1,002
  • 7
  • 19

2 Answers2

11

For me the solution was loginctl enable-linger username. Without this the service would die when the user logged out. https://wiki.archlinux.org/index.php/Systemd/User#Automatic_start-up_of_systemd_user_instances

burneddi
  • 220
  • 1
  • 4
6

You can change logind configuration:

/etc/systemd/logind.conf

[Login]
…
KillUserProcesses=no
…

This also changes behavior for other services and background processes (like screen, tmux). See issue #3483;


Run systemctl restart systemd-logind after that.

jiwopene
  • 1,002
  • 7
  • 19