Ubuntu – Trying to setup user systemd service: Loaded: not-found (Reason: No such file or directory)

16.04servicessystemd

I'm trying to make a user systemd service that runs a python script – however, when I try starting the service with systemctl --user start shadesmath, and then do systemctl status shadesmath, I get:

‚óŹ shadesmath.service
   Loaded: not-found (Reason: No such file or directory)
   Active: inactive (dead)

Here is the contents of my shadesmath.service file, which has been placed in ~/.config/systemd/user/shadesmath.service with permissions 744:

[Unit]
Description=ShadesMath
AssertPathExists=/home/mikel/bots/mathbot/mathbot

[Service]
WorkingDirectory=/home/mikel/bots/mathbot/mathbot
ExecStart=/home/mikel/anaconda3/bin/python bot.py parameters.json
Restart=always

[Install]
WantedBy=default.target

I tried running systemctl --user enable shadesmath, which created a symlink to the service in ~/.config/user/systemd/default.target.wants, but this hasn't seemed to change anything when I try starting the service.

This is my first time trying to use systemd, so chances are I'm doing something stupid, but I can't figure out what the issue is. Any pointers on how to set this up would be much appreciated. My goal is to have a service that runs this python script, and to re-run it on startup/if the script finishes or crashes – ideally I want this to be a user service as I don't want this running as root.

Best Answer

After creating or changing the unit file, you need to tell systemd to reload it:

systemctl --user daemon-reload

This explains why a reboot fixed it for @noraj.

Related Question