I have a very simple systemd
service:
[Unit]
Description=throttle service
[Service]
ExecStart=%h/.local/bin/throttle --server
Type=simple
Restart=always
RestartSec=3
[Install]
WantedBy=default.target
The executed service runs the command mbsync [something]
in a python subprocess
with shell=False
.
I have 3 copies of mbsync
installed:
❯ which -a mbsync
/home/fbence/.local/bin/mbsync
/home/fbence/.local/bin/mbsync
/usr/bin/mbsync
/bin/mbsync
Running mbsync
from the login shell will obviously run the top one in ~/.local
. If I manually start the systemd
service, as in systemctl --user start throttle.service
it also picks up this one. If I reboot my system, then it seems to pick up one of the other (older) versions as I see errors in journalctl
, where it is trying to access the config file for older version. If I manually stop and restart the service (systemctl --user stop/start
) it works again correctly.
Why is this not consistent? What's the difference between me starting it and it starting on boot? How do I fix this to work also on boot?
Update
After some debugging I found that /usr/libexec/gdm-x-session
logs some info about running dbus-update-activation-environment
. I tested and adding an ExecStartPre=/bin/sleep 30
solves the issue. So now my question is actually: how do I setup the service to wait for this to happen in a less hacky way?
~/.profile
(which is where Ubuntu adds ~/.local/bin to the PATH). You could try creating a custom~/.config/environment.d/
file containing the modified PATH as described here Environment variablesdbus-update-activation-environment
can set some stuff, but I can't figure out what I need to wait on.WantedBy=graphical-session.target
instead ofWantedBy=default.target
or useAfter=graphical-session.target
or both for example.