| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
# needrestart - Restart daemons after library updates. |
| 4 |
# |
| 5 |
# Restarting `systemd --user` by signaling it with SIGRTMIN+25. |
| 6 |
# (documented in systemd(1) as equivalent to `systemctl --user daemon-reexec`, |
| 7 |
# but easier to do outside of a user session) |
| 8 |
# |
| 9 |
|
| 10 |
# enable xtrace if we should be verbose |
| 11 |
if [ "$NR_VERBOSE" = '1' ]; then |
| 12 |
set -x |
| 13 |
fi |
| 14 |
|
| 15 |
# also possible to use `--value` (systemd 230+) |
| 16 |
systemctl show --state=active --property=MainPID 'user@*.service' | while IFS='=' read -r _ pid; do |
| 17 |
# skip empty lines produced by `systemctl show` if the property |
| 18 |
# did not exist or could not be queried |
| 19 |
if [ -z "$pid" ]; then continue; fi |
| 20 |
|
| 21 |
# use `env` to suppress the `kill` builtin, which might not know about |
| 22 |
# RT signals (or about _enough_ RT signals, e.g., dash) |
| 23 |
# also possible as: `systemctl kill --kill-whom=main --signal='SIGRTMIN+25' "$unit"` (systemd 252+) |
| 24 |
# also possible as: `systemctl -M "[email protected]" --user daemon-reexec` (systemd 248+) |
| 25 |
env kill -SIGRTMIN+25 "$pid" |
| 26 |
done |