From 919213be6334e8d73c929876417c94f2856e5b25 Mon Sep 17 00:00:00 2001 From: Colin Guthrie Date: Tue, 3 Apr 2012 00:19:15 +0000 Subject: add-service: on package upgrade, restart all instances of template units. --- add-service | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'add-service') diff --git a/add-service b/add-service index ac1d29b..7e00cce 100755 --- a/add-service +++ b/add-service @@ -260,8 +260,23 @@ else if [ x$init = xsystemd ]; then # Package install may have changed the unit file, so reload the daemon # before trying to restart anything - /bin/systemctl --system daemon-reload - /bin/systemctl --quiet try-restart $units + if [ x$reloaded = xno ]; then + /bin/systemctl --system daemon-reload + fi + # There may be template units, so attempt to find all instances and + # restart them. + for unit in $units; do + if [[ "$unit" =~ "@.service" ]]; then + instances=$(/bin/systemctl -a --full list-units | grep -E "${unit%@.service}@[^ ]+.service" | awk '{ print $1 }') + if [ -n "$instances" ]; then + for iunit in $instances; do + /bin/systemctl --quiet try-restart $iunit + done + fi + else + /bin/systemctl --quiet try-restart $unit + fi + done elif [ -f /etc/rc.d/init.d/$srv ]; then script=$(check_sysvinit_service 3 $srv); if [ -f "$script" ]; then -- cgit v1.2.1