1

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?

9
  • I'm kind of surprised it works when you start the service manually, since AFAIK systemd user units do not inherit environment variables set in places like ~/.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 variables Commented Mar 5 at 12:46
  • @steeldriver they don't but it seems dbus-update-activation-environment can set some stuff, but I can't figure out what I need to wait on.
    – fbence
    Commented Mar 5 at 14:07
  • 1
    You might want to use WantedBy=graphical-session.target instead of WantedBy=default.target or use After=graphical-session.target or both for example.
    – Raffa
    Commented Mar 5 at 14:23
  • @fbence ah! interesting yes that would explain it Commented Mar 5 at 14:30
  • 1
    @steeldriver I too confuse them and others all the time :D ... fbence You might find Command to list systemd services that run on startup in the order in which they run? helpful in identifying the order in which the user units are run on your system..
    – Raffa
    Commented Mar 6 at 14:24

0

You must log in to answer this question.

Browse other questions tagged .