4

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.

2
  • The issue seems to have fixed itself with some more fiddling (redoing the steps in the question) but unfortunately I don't know what actually ended up fixing it.
    – mxbi
    Apr 1, 2018 at 16:12
  • To get insights about issues do sudo systemd-analyze verify NAME.service. To me it reported that WorkingDirectory is not a valid directive. Oct 7, 2022 at 18:31

2 Answers 2

5

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.

2
  • didn't really fix in my case. Reloaded the daemon, rebooted the system, disabled/enabled the service (and getting symlinks created). I get prompted a password when running service myservice start, even though I configured it as --user service. And after giving the password, it says that the service was not found 😕 Oct 7, 2022 at 18:33
  • @Kamafeather The service command only lets you control system services (as far as I know). You need to use systemctl directly.
    – Thomas
    Oct 7, 2022 at 18:44
1

I had the same problem; logging out and back in did not work but the answer was very simple: just reboot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.