-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck_restart.sh
executable file
·62 lines (54 loc) · 1.07 KB
/
check_restart.sh
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
# Check which services need restarting
# Services that must not be restarted are blacklisted
set +H
CHECKRESTART=needs-restarting
SERVICES=
RES=0
MSG=""
BLACKLIST=(
"auditd.service"
"dbus.service"
"dbus-broker.service"
"sshd.service"
"user@[0-9]\+.service"
"nfs-server.service"
"nfs-mountd.service"
"nfsdcld.service"
"rpc-statd.service"
)
if (( $# != 0 )) ; then
echo "Usage: ./check_restart.sh"
exit 3
fi
SERVICES=$($CHECKRESTART -s 2>/dev/null | grep "\.service" | tr "\n" ";")
for s in ${BLACKLIST[@]}; do
SERVICES=$(/bin/echo "${SERVICES}" | /bin/sed "s/${s};//g")
done
if [ -n "$SERVICES" ] ; then
RES=2
MSG="Services need restarting:$SERVICES"
fi
$($CHECKRESTART -r 1>/dev/null)
if [ $? -ne 0 ] ; then
MSG="Server needs reboot;$MSG"
fi
case ${RES} in
0)
echo "OK - $MSG"
exit 0
;;
1)
echo "CRITICAL - $MSG"
exit 2
;;
2)
echo "WARNING - $MSG"
exit 1
;;
*)
echo "CRITICAL - undefined error"
exit 2
;;
esac
exit 3