torfsen/python-systemd-tutorial

Missing ~/.config/systemd/user/ on session start

k-husmann opened this issue · 2 comments

Seems like the ~/.config/systemd/user/ directory needs to exist prior session start, otherwise systemd behaves weird:

  • I logged in, created that directory and a unit file therein.
  • systemctl --user list-unit-files listed the newly created unit file just fine,
  • but systemctl --user start my... gave an error like that:
$> systemctl --user start mytestunit.service
Failed to start mytestunit.service: Unit mytestunit.service not found.`

It took me a while to debug that. In the end, I just run sudo reboot and from there on everything worked fine - just as explained in your repo. Also with newly created unit files. That's why I expect that this directory needs to exist prior user session start, otherwise the user units don't really work.
Btw. daemon-reload did not help.

Maybe you should mention this as a hint in your beautiful tutorial.

((NB: the reboot was easier than session restart, as I was connected to a raspberry via ssh, ssh relogin did not suffice - b/c that did not terminate the user session I suppose))

I had the same problem, and I think running systemctl --user enable my_service weirdly solved it.
At this time I hadn't added the [Install] part so the enable command did not worked but after that the start worked 🤷🏻‍♂️

@k-husmann: Thanks for the report!

It seems that you need to run systemctl --user daemon-reload before systemd really finds the new unit. Should be fixed as of #10.