Why won't my enabled systemd service start on boot?

I have no idea why but to get this to work I:

deleted Environment=DISPLAY=:%i

added a User= variable

Made sure the correct file was in /etc/systemd/system/emacs.service (earlier it had been a hard link)

and re-ran systemctl enable emacs

This made it work.

EDIT The real problem here is that I had a typo at line 3: Documentatin

I found this by checking journalctl. I suggest anyone who has issues with a systemd script do the same as there was no error sent to stderr.


ooh this is interesting.

Picking a random service unit and staring at it, it depends on a specific target instead of default.target. The latter is symbolic... a configured link to a specific target, semantically it doesn't make sense. (See systemctl set-default)

That might explain why your service shows as disabled after you enable it. Try replacing default.target in your service file with multi-user.target, for example.

(Not reporting an error when failing to enable seems like a defect in systemd. I almost wonder if you now have a directory /etc/systemd/system/default.target.wants).


You have a DISPLAY environment variable, that means you want X11 to be started. So you need to have a way to block your service until then.

This is done using the After=... option.

I haven't done it myself, so I cannot say that it would work, but it is likely something to do with graphical.target.

[Unit]
After=graphical.target

Another possibility, if the X server does not start immediately (i.e. you have a login screen with lightdm or such), then you may have to use WantedBy=... instead:

[Unit]
WantedBy=graphical.target

If you get tired of getting it to work with systemd, you may want to look into the usual way X-Windows managers make it work.

There is the ~/.xprofile file, which works like the ~/.bashrc file.

There is also the ~/.config/autostart/*.desktop files. It will automatically start whatever applications are defined in there.

These solutions are not system wide, though, in case you have multiple users, each one would have to have its own entry. Also, it does not start the application as root, but you, instead.


As a side note, the "loaded + inactive (dead)" message means that systemd had a hard time to start the process and as a result decided to abandon it. You can manually test that the name.service works once you rebooted using:

systemctl stop <service-name>
systemctl start <service-name>

This will refresh the status and start the service properly, assuming the info is correct. You can then check the status again to see additional details:

 systemctl status <service-name>

Tags:

Systemd