4

I want the systemd per-user instance to start a following service unit at bootup:

user.name@svr:~$ systemctl --user cat tmux
# /etc/systemd/user/tmux.service
[Unit]
Description=Start tmux in detached session

[Service]
Type=forking
ExecStart=/usr/bin/tmux new-session -s test -d
ExecStop=/usr/bin/tmux kill-session -t test
Restart=always
RestartSec=1

[Install]
WantedBy=default.target
user.name@svr:~$

Lingering is enabled:

user.name@svr:~$ sudo loginctl show-user user.name | grep Linger=
Linger=yes
user.name@svr:~$

However, when I restart the server, then service is not started:

user.name@svr:~$ systemctl --user status tmux
● tmux.service - Start tmux in detached session
   Loaded: loaded (/etc/systemd/user/tmux.service; enabled; vendor preset: enabled)
   Active: inactive (dead)
user.name@svr:~$

I can start the tmux service manually with systemctl --user status tmux without any issues. Also, according to systemctl --user status the systemd per-user instance itself is running:

user.name@svr:~$ systemctl --user status 
● svr
    State: running
     Jobs: 0 queued
   Failed: 0 units
    Since: Tue 2019-12-03 22:02:41 UTC; 15min ago
   CGroup: /user.slice/user-1000.slice/[email protected]
           └─init.scope
             ├─456 /lib/systemd/systemd --user
             └─462 (sd-pam)
user.name@svr:~$ 

This should mean that there are no issues with Linux PAM configuration.

Why doesn't systemd per-user instance start a service unit automatically?

2
  • 1
    Works OK for me on ubuntu. When you restart the server are you logging in, I presume?
    – rogerdpack
    Dec 3, 2019 at 16:57
  • Yes, I log in. However, I expect this to work even without logging in.
    – Martin
    Dec 3, 2019 at 17:20

1 Answer 1

3

I enabled(systemctl --user enable tmux) the tmux.service at the time when I had WantedBy=multi-user.target in the [Install] section of the /etc/systemd/user/tmux.service and later forgot to re-enable the service. Checking the content of the ~/.config/systemd/user/ directory helped me to spot my mistake.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .