Bug 86727

Summary: RFE: systemctl --user should allow to specify which user we want to query/update
Product: systemd Reporter: Mildred Ki'Lya <mildred-bug.freedesktop>
Component: generalAssignee: systemd-bugs
Status: NEW --- QA Contact: systemd-bugs
Severity: normal    
Priority: medium    
Version: unspecified   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:

Description Mildred Ki'Lya 2014-11-26 08:33:53 UTC
It should be possible as root to look at / update user units for selected users. Especially since some of these users might not have tha ability to log in at all (system-like users).

The use case that led to this bug report involves enabling and starting a user unit for a 'pulseaudio' user running a 'pulseaudio.service' unit in order to have a network sound server. The 'pulseaudio' user is set to have no password (and this cannot login) and  starts at boot because it was configured using 'loginctl enable-linger pulseaudio'

What I wanted to do was:

    systemctl --user=pulseaudio enable pulseaudio.service
    systemctl --user=pulseaudio start pulseaudio.service
    systemctl --user=pulseaudio status pulseaudio.service

(but the --user option do not take an argument)

What I tried to do instead was:

    sudo -u pulseaudio systemctl --user enable pulseaudio.service
    sudo -u pulseaudio systemctl --user start pulseaudio.service
    sudo -u pulseaudio systemctl --user status pulseaudio.service

(or some other variation using 'su' or 'su -l' instead of 'sudo')

That didn't work because the XDG_RUNTOME_DIR was not set. This could have been caused by either (or both):

* /etc/pam.d/{su,su-l,sudo} not using the pam_systemd.so module at all

* pam_systemd.so not setting the environment variable. I suggest you look at
  bug reports like https://bugzilla.redhat.com/show_bug.cgi?id=753882 or
  bug #70810

What I ended up doing was something like:

    su pulseaucio -c '
      XDG_RUNTIME_DIR=/run/user/$(id -u)
      systemctl --user enable pulseaudio.service
      systemctl --user start pulseaudio.service
      systemctl --user status pulseaudio.service
    '

I don't loke it, especially setting the XDG_RUNTIME_DIR that was. This is implementation specific and not portable. That's why I suggest you provide a way to select the user session on the command line.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.