aboutsummaryrefslogtreecommitdiffstats
path: root/roles/nagios_client/files/usr/lib64/nagios/plugins/check_needs_restart
blob: b1484cd12957d9570255d35120c2e4eb4b339ba3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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