You are not logged in.

#1 2016-05-04 13:11:37

jobach
Member
Registered: 2015-09-28
Posts: 5

Start systemd unit for all running user instances

Is there a natural way to start a given unit (e.g. foo.target) globally for all running user-instances?

The --global option sadly only works with enable, not with start, so

$ systemctl --global start foo.target

does not work.

A hack would be sth. like:

#!/bin/sh

unit_name=foo.target

# All running user-instances
users=$(systemctl list-units --no-legend 'user@*.service' | sed 's/user@\([0-9]*\).*/\1/' \
                     | xargs -I {} getent passwd {} | cut -d: -f1,3)

for user in $users
do
   uid=${user#*:}
   name=${user%:*}

   DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$uid/bus" \
         su $name -c "systemctl --user start $unit_name"
done

But there should really be a more natural way. Is there a specific reason --global does not work with start?

I would post this in a systemd-forum, but I don't think there is any.

Last edited by jobach (2016-05-04 23:16:30)

Offline

Board footer

Powered by FluxBB