]> code.delx.au - monosys/commitdiff
improved find-services-to-restart
authorJames Bunton <jamesbunton@delx.net.au>
Wed, 11 Feb 2015 10:35:16 +0000 (21:35 +1100)
committerJames Bunton <jamesbunton@delx.net.au>
Wed, 11 Feb 2015 10:35:16 +0000 (21:35 +1100)
scripts/find-services-to-restart

index 65a1f9c4f98fbb36daae03c2518085f3ca6e48b3..4c2a747bc69e77b4a2a77aee3ba28bae56eb6d7f 100755 (executable)
@@ -1,7 +1,14 @@
 #!/bin/bash
 
-for pid in $(sudo lsof +c 0 / | grep DEL | awk '{print $2}'); do
-    echo -n "sudo systemctl restart "
-    systemctl status "$pid" | head -n1 | awk '{print $2}'
-done
+for pid in $(sudo lsof +c 0 / | grep DEL | awk '{print $2}' | sort -u); do
+    if [ "$pid" = 1 ]; then
+        echo "sudo systemctl daemon-reexec"
+        exit 0
+    fi
+
+    service="$(systemctl status "$pid" | head -n1 | awk '{print $2}')"
+    if [ -n "$service" ]; then
+        echo "sudo systemctl restart $service"
+    fi
+done | sort -u