Skip to content
checkservices 595 B
Newer Older
Seblu's avatar
Seblu committed
#!/bin/bash
# Copyright © Sébastien Luttringer
# Restart running systemd service if a new binary is available

(( $UID != 0 )) && echo 'You need to be root' && exit 1

declare -a services
services=($(systemctl -t service --full|grep \.service|grep running|sed -rn 's/^(.*\.service).*/\1/p'))

for svc in "${services[@]}"; do
	pid=$(systemctl show "$svc"|sed -nr 's/^MainPID=(.*)/\1/p')
	if readlink "/proc/$pid/exe"|grep -q '(deleted)'; then
		echo systemctl restart "$svc"
		[[ $1 == '-f' ]] && systemctl restart "$svc"
	fi
done

[[ -t 2 && $1 != '-f' ]] && echo 'Use -f to execute' >&2 || :