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?

fbence
  • 234
  • 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 – steeldriver Mar 05 '24 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 Mar 05 '24 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 Mar 05 '24 at 14:23
  • @fbence ah! interesting yes that would explain it – steeldriver Mar 05 '24 at 14:30
  • @steeldriver You're absolutely right about system and user units cannot reference each other but that one is the "current graphical user session target" systemctl --user status graphical-session.target – Raffa Mar 05 '24 at 14:36
  • it looks like that target is never started for me @Raffa, probably because I have Regolith on top of Ubuntu ... I'll have to investigate a bit more I guess. – fbence Mar 05 '24 at 14:42
  • @Raffa ah my bad I was confusing graphical-session.target with graphical.target – steeldriver Mar 05 '24 at 15:01
  • 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 Mar 06 '24 at 14:24
  • @Raffa nice one, thanks, I will investigate! – fbence Mar 06 '24 at 19:51

0 Answers0