-
Notifications
You must be signed in to change notification settings - Fork 9
/
check_proc_status.sh
68 lines (62 loc) · 1.62 KB
/
check_proc_status.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
62
63
64
65
66
67
68
#!/bin/bash
#
# Nagios plugin check_proc_status.sh
#
# Version: 1.0, released on 10/08/2010, tested on Debian GNU/Linux 5.0 (lenny).
#
# This plugin checks status of /etc/init.d scripts.
#
# Copyright (c) 2010 by Kees Meijs <[email protected]> for Kumina bv.
#
# This work is licensed under the Creative Commons Attribution-Share Alike 3.0
# Unported license. In short: you are free to share and to make derivatives of
# this work under the conditions that you appropriately attribute it, and that
# you only distribute it under the same, similar or a compatible license. Any
# of the above conditions can be waived if you get permission from the copyright
# holder.
# Default exit codes.
OK=0;
WARNING=1;
CRITICAL=2;
UNKNOWN=3;
# Not enough arguments makes no sense.
if [ ${#} -lt 1 ]; then
echo "No script to check."
exit ${UNKNOWN}
fi
# Check if script exists and is executable.
if [ ! -x "/etc/init.d/${1}" ]; then
echo "Script does not exist or is not executable."
exit ${CRITICAL}
fi
# Not being root makes no sense.
if ([ `id -u` != "0" ]); then
echo "We're a non-privileged user. Not all scripts support that."
exit ${UNKNOWN}
fi
# Ask script for status.
/etc/init.d/${1} status &> /dev/null
RETVAL=${?}
# Act on certain return values (LSB).
case ${RETVAL} in
0)
echo "Service ${1} OK."
exit ${OK}
;;
1)
echo "Service ${1} is dead but /var/run PID file exists."
exit ${CRITICAL}
;;
2)
echo "Service ${1} is dead but /var/lock lock file exists."
exit ${CRITICAL}
;;
3)
echo "Service ${1} is not running."
exit ${CRITICAL}
;;
*)
echo "Service ${1} is unknown."
exit ${UNKNOWN}
;;
esac