I cannot get user units to start automatically after reboot.
1: I’ve created a user unit file /home/test/.config/systemd/user/test.service (essentially a “sleep 3600”)
2: Reloaded the daemon “systemctl --user daemon-reload”
3: Enabled the service. Although it produced a weird error message:systemctl --user enable test
Failed to enable unit: File /home/test/.config/systemd/user/test.service already exists.
4: Start/stop of service works
5: Reboot machine
User service is not started. The processes systemd and (sd-pam) are running but not the service. Start/stop of service works.
What am I doing wrong? The goal is to have the user service automatically start after a reboot.
I don’t like the error messages I get in step but all the guides I’ve found points to that file location for the service file, and aside from not starting after reboot it seems to work.
Hi and welcome to the Forum
Did you add a WantedBy= entry in your service? also did you run loginctl enable-linger USERNAME as well to enable at boot rather than login.
Yes, I did a “loginctl enable-linger test” - I forgot to list that in my original post. That seems to start systemd and (sd-pam) as it should after reboot, but from there on the user systemd seems to be unhappy about something as it doesn’t start the service automatically.
test@isjsys4:~> systemctl --user list-units --type=target
UNIT LOAD ACTIVE SUB DESCRIPTION
basic.target loaded active active Basic System
default.target loaded active active Default
paths.target loaded active active Paths
sockets.target loaded active active Sockets
timers.target loaded active active Timers
LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.
5 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
I tried that now, but it made no differences. Still only systemd and sd-pam is running for that user.
If the unit file in its [Install] section has an Alias that happens to be the same as the unit file name (sans .service) then while enabling the service this unhelpful warning message appears:
Failed to enable unit: File /home/test/.config/systemd/user/test.service already exists.
and the unit/service is halfway loaded. It can be started, stopped, restarted, status queried, etc, but after reboot it isn’t automatically started.