4

So I have this scenario: user-a is running a systemd user service user-a-service. I'm root and I want to restart that user service. I can't find a way to do so. Basically I want this:

systemctl --user user-a restart user-a-service

Please not that this not a normal system service running with a specific non-root user but an actual user service.

1 Answer 1

5

The only way to do this is by running systemctl as that user – and with the apropriate environment variables to allow it to find either the D-Bus user bus or the private systemd socket:

sudo -u user-a XDG_RUNTIME_DIR="/run/user/$(id -u user-a)" systemctl --user restart user-a-service

With newer systemd (v248), you can use --machine for loopback connections by specifying the special hostname .host; it will handle environment setup by calling PAM(login) automatically:

systemctl --machine [email protected] --user restart user-a-service

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .