1

I am trying to start a systemd user service at user login. But my service keep starting at boot and remain running after I logout. I am on Linux Mint 21.2. Here is what I did so far.

  • Create unit file in /usr/lib/systemd/user/mpd.service with following content
[Unit]
Description=Music Player Daemon

[Service] ExecStart=/usr/bin/mpd --no-daemon

[Install] WantedBy=default.target

  • Enable with sudo systemctl --global enable mpd.service
  • Reload daemon systemctl --user daemon-reload
  • Logout and log back in. Nothing started.
  • Reboot and the service started. After I logout, the service still keep running.

There is a similar question here. But I don't get the behavior described in the answers there.

2 Answers2

1

According to the item you linked, you need to sudo systemctl --user enable mpd.service instead of --global.

The idea is that when you use --user enable, you're enabling this for THIS USER ONLY. --global means you are enabling for all users.

Giacomo1968
  • 55,001
1

my service keep starting at boot and remain running after I logout

You probably have logind's "linger mode" active for your account. This switches the entire user service manager from being session-bound to being permanent. Look in /var/lib/systemd/linger to check if that's the case.

The other possibility is that you have an SSH connection active, or – in some distributions – a Cron job running; those might also be set up to count as "sessions".

With PulseAudio/PipeWire this shouldn't be a problem anyway, as they relinquish the audio output when you log out, so mpd should pause but can keep running.

There are other .targets that are directly associated with your graphical environment which you could use instead of "default.target", though nothing generic.

u1686_grawity
  • 452,512
  • There is a file in /var/lib/systemd/linger whose filename is my username, but it's an empty file. Does that mean linger is active? – debugger101 Jan 15 '24 at 20:47
  • Lingering was indeed enabled by something that I am not aware of. Disabling it with loginctl disable-linger $(whoami) solve the problem. Thanks. – debugger101 Jan 16 '24 at 21:01