summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-12-19 16:35:58 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2015-12-19 16:35:58 +0000
commit8849a97f67d0a75b22dce75b852c739585d161fc (patch)
treef8dac614e4a7d049d99ee549b18a230735e7e95e
parentsquid.service (diff)
downloadutil-autorestart-0.1.tar.bz2
util-autorestart-0.1.tar.xz
util-autorestart-0.1.zip
Initial commit of autorestartautorestart-0.1
-rw-r--r--autorestart/etc/ignore.d/dm1
-rw-r--r--autorestart/etc/ignore.d/scope1
-rwxr-xr-xautorestart/scripts/95-systemd-restart-as-needed34
3 files changed, 36 insertions, 0 deletions
diff --git a/autorestart/etc/ignore.d/dm b/autorestart/etc/ignore.d/dm
new file mode 100644
index 0000000..01b38b3
--- /dev/null
+++ b/autorestart/etc/ignore.d/dm
@@ -0,0 +1 @@
+dm\.service$
diff --git a/autorestart/etc/ignore.d/scope b/autorestart/etc/ignore.d/scope
new file mode 100644
index 0000000..2d69b87
--- /dev/null
+++ b/autorestart/etc/ignore.d/scope
@@ -0,0 +1 @@
+\.scope$
diff --git a/autorestart/scripts/95-systemd-restart-as-needed b/autorestart/scripts/95-systemd-restart-as-needed
new file mode 100755
index 0000000..c8099ee
--- /dev/null
+++ b/autorestart/scripts/95-systemd-restart-as-needed
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+TMP="/tmp"
+DELETED="$TMP/restart.deleted"
+OWNED="$TMP/restart.owned"
+UPDATED="$TMP/restart.updated"
+UNITS="$TMP/restart.units"
+
+lsof -n | awk '{ if ($5 == "DEL" || $10 == "(deleted)") print $9,$2; }' | sort -uk 1,2 > $DELETED
+find /var/db/pkg/ -name CONTENTS | xargs cat | awk '{ if ($1 != "dir") print $2; }' | xargs realpath 2> /dev/null | sort > $OWNED
+join $DELETED $OWNED | awk '{ print $2 }' | sort -gu > $UPDATED
+
+(for pid in $(cat $UPDATED) ; do
+ systemctl status $pid | head -n 1
+done) | sort -u > $UNITS
+
+if [ -s $UNITS ] ; then
+ (
+ echo "Restarting units:"
+ for unit in $(awk '{print $2}' $UNITS) ; do
+ if ( echo $unit | grep $( ls -1 /etc/autorestart/ignore.d/* | sed -e 's/^/-f /' ) > /dev/null ) ; then
+ echo "Skipping $unit"
+ else
+ systemctl restart $unit
+ systemctl status $unit
+ fi
+ echo
+ done
+ ) | mailx -a "Content-Type: text/plain; charset=utf-8" \
+ -s "$(hostname) systemd units requiring restart" $(whoami)
+fi
+
+rm -f $TMP/restart.*
+