aboutsummaryrefslogtreecommitdiffstats
path: root/roles/nagios_client/files/usr/lib64/nagios/plugins/check_needs_restart
diff options
context:
space:
mode:
authorStonewall Jackson <stonewall@sacredheartsc.com>2023-02-04 01:23:43 -0500
committerStonewall Jackson <stonewall@sacredheartsc.com>2023-02-04 01:52:13 -0500
commit0261e875679f1bf63c8d689da7fc7e014597885d (patch)
tree3f19cd74a0c1070944f75437f30b098d6ef2ffcb /roles/nagios_client/files/usr/lib64/nagios/plugins/check_needs_restart
downloadselfhosted-0261e875679f1bf63c8d689da7fc7e014597885d.tar.gz
selfhosted-0261e875679f1bf63c8d689da7fc7e014597885d.zip
initial commit
Diffstat (limited to 'roles/nagios_client/files/usr/lib64/nagios/plugins/check_needs_restart')
-rw-r--r--roles/nagios_client/files/usr/lib64/nagios/plugins/check_needs_restart30
1 files changed, 30 insertions, 0 deletions
diff --git a/roles/nagios_client/files/usr/lib64/nagios/plugins/check_needs_restart b/roles/nagios_client/files/usr/lib64/nagios/plugins/check_needs_restart
new file mode 100644
index 0000000..b1484cd
--- /dev/null
+++ b/roles/nagios_client/files/usr/lib64/nagios/plugins/check_needs_restart
@@ -0,0 +1,30 @@
+#!/bin/bash
+
+set -Eeu -o pipefail
+
+trap 'exit 3' ERR
+
+NEEDS_RESTARTING_STDOUT=$(sudo dnf needs-restarting --reboothint) || NEED_REBOOT=$? && NEED_REBOOT=$?
+STALE_SERVICES=($(sudo dnf needs-restarting --services 2>/dev/null | sed '/^user@/d'))
+
+if (( NEED_REBOOT == 1 )); then
+ echo 'Reboot needed to apply package updates.'
+ RC=1
+elif (( ${#STALE_SERVICES[@]} > 0 )); then
+ echo 'One or more services need restarting.'
+ RC=1
+else
+ echo 'Everything is up to date.'
+ RC=0
+fi
+
+printf '%s\n\n' "${NEEDS_RESTARTING_STDOUT}"
+
+if (( ${#STALE_SERVICES[@]} > 0 )); then
+ echo 'The following services need restarting to apply package updates:'
+ printf ' * %s\n' "${STALE_SERVICES[@]}"
+else
+ echo "All running services are up to date."
+fi
+
+exit $RC