Bug 86727 - RFE: systemctl --user should allow to specify which user we want to query/update
Summary: RFE: systemctl --user should allow to specify which user we want to query/update
Status: NEW
Alias: None
Product: systemd
Classification: Unclassified
Component: general (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: systemd-bugs
QA Contact: systemd-bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-11-26 08:33 UTC by Mildred Ki'Lya
Modified: 2014-12-08 23:19 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

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.