Commit e016f296 authored by Seblu's avatar Seblu
Browse files

Add restart-updated-service

This script list (and restart) updated (file speaking) services running on
the host.
parent 205f42cb
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ package() {
  install -m644 COPYRIGHT LICENSE "$pkgdir/usr/share/licenses/$pkgname"
  # install binaries
  install -m755 atc aurdown go2chroot	addpkg sign archbuild-dl pkgbuild2json \
    tmpmakepkg reinstallpkgs "$pkgdir/usr/bin"
    tmpmakepkg reinstallpkgs restart-updated-service "$pkgdir/usr/bin"
}

# vim:set ts=2 sw=2 et:
+18 −0
Original line number Diff line number Diff line
#!/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 || :