diff options
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_restart | 30 |
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 |