Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'jb48950' into 'master'
[systemd] Fix systemctl-user script. Contributes to JB#48950

See merge request mer-core/systemd!35
  • Loading branch information
Matti Kosola committed Aug 26, 2020
2 parents 21fef17 + 734ec31 commit fba4bc0
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions rpm/systemctl-user
Expand Up @@ -2,8 +2,8 @@
#
# This file is part of systemd.
#
# Copyright (C) 2013 Jolla Ltd.
# Contact: Pekka Lundstrom <pekka.lundstrom@jolla.com>
# Copyright (C) 2020 Jolla Ltd.
# Contact: Franz-Josef Haider <franz.haider@jolla.com>
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
Expand All @@ -21,23 +21,13 @@
#
# This is helper script that can be used to run systemctl commands on user
# session when logged in as root
# It scans all running sessions and runs the command for each user
# It searches for the active user session and runs the command for that user
# Usage:
# systemctl-user <any systemctl command with parameters>
# example:
# systemctl-user stop myapp.service

# First check that we are running in env where this works
# (rpm build envs don't have all tools)
which pidof &> /dev/null && which cut &> /dev/null && which ps &> /dev/null || exit 1
# Get all running systemd user sessions
SESSION_PIDS=$(pidof systemd | cut -sd " " -f2-)
[ -z "$SESSION_PIDS" ] && echo "systemd user session is not running" && exit 1
MY_ARGS=$@
for PID in $SESSION_PIDS; do
U_NAME=$(ps -o user= $PID)
#echo "$U_NAME: systemctl --user $MY_ARGS"
su -l $U_NAME -c "systemctl --user $MY_ARGS"
done

USER_ID=$(id -u $(loginctl list-sessions | grep seat0 | tr -s " " | cut -d " " -f 4))
export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$USER_ID/dbus/user_bus_socket"

systemctl --user $@

0 comments on commit fba4bc0

Please sign in to comment.