1

From a script that runs as root, I'd like to start a systemd user service.

I've tried the most obvious thing:

sudo -u $user systemctl --user <etc>

but I get Failed to connect to bus: No such file or directory - I assume this is referring to the dbus system bus.

Do I need to set DBUS_SYSTEM_BUS_ADDRESS? How would I find out what to set it to?

Or is there a different way to interact with another user's systemd?

Brendan
  • 111
  • 2
  • 1
    To be clear, you don't want to start the service at boot, and you don't want to run it as a system service under a non-root user? – Michael Hampton Dec 31 '18 at 06:25
  • Both correct. The actual context is that I want to start a user service from NetworkManager's "dispatcher" when it connects to a VPN. – Brendan Dec 31 '18 at 06:29
  • 1
    But the user is not logged in at the time? – Michael Hampton Dec 31 '18 at 06:40
  • Yeah, the user is logged in and their `systemd --user` is running – Brendan Dec 31 '18 at 09:05
  • 1
    See https://serverfault.com/a/937012/126632 as I suspect your issue is closely related to that. – Michael Hampton Dec 31 '18 at 15:00
  • Hmm, setting XDG_RUNTIME_DIR didn't change the result. I also checked `env | grep /run/user` as `$user` to see if there was anything similar that might be influencing how `systemctl` connects to `systemd`. I found XDG_SESSION_BUS_ADDRESS but setting that also had no effect. – Brendan Jan 04 '19 at 04:44

0 Answers0