<html>
    <head>
      <base href="https://bugs.freedesktop.org/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - systemctl --user should allow to specify which user we want to query/update"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=86727">86727</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>systemctl --user should allow to specify which user we want to query/update
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>systemd
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Other
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>medium
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>general
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>systemd-bugs@lists.freedesktop.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>mildred-bug.freedesktop@mildred.fr
          </td>
        </tr>

        <tr>
          <th>QA Contact</th>
          <td>systemd-bugs@lists.freedesktop.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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 <a href="https://bugzilla.redhat.com/show_bug.cgi?id=753882">https://bugzilla.redhat.com/show_bug.cgi?id=753882</a> or
  <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - libpam-systemd does not change XDG_RUNTIME_DIR when using su - username"
   href="show_bug.cgi?id=70810">bug #70810</a>

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.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the QA Contact for the bug.</li>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>