]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/sh | |
2 | # | |
3 | # Nagios Host/service/network monitoring daemon | |
4 | # | |
5 | # chkconfig: 345 85 24 | |
6 | # description: Host/service/network monitoring daemon which uses snort as NIDS | |
7 | # | |
8 | ||
9 | # Source function library | |
10 | . /etc/rc.d/init.d/functions | |
11 | ||
12 | # Get network config | |
13 | . /etc/sysconfig/network | |
14 | ||
15 | # Get service config | |
16 | [ -f /etc/sysconfig/nagios ] && . /etc/sysconfig/nagios | |
17 | ||
18 | # Check that networking is up. | |
19 | if is_yes "${NETWORKING}"; then | |
20 | if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then | |
21 | msg_network_down "Nagios" | |
22 | exit 1 | |
23 | fi | |
24 | else | |
25 | exit 0 | |
26 | fi | |
27 | ||
28 | # configtest itself | |
29 | configtest() { | |
30 | /usr/sbin/nagios -v /etc/nagios/nagios.cfg 2>&1 | |
31 | return $? | |
32 | } | |
33 | ||
34 | # wrapper for configtest: | |
35 | checkconfig() { | |
36 | local details=${1:-0} | |
37 | ||
38 | if [ $details = 1 ]; then | |
39 | # run config test and display report (status action) | |
40 | show "Checking %s configuration" "Nagios"; busy | |
41 | local out | |
42 | out=`configtest 2>&1` | |
43 | RETVAL=$? | |
44 | if [ $RETVAL = 0 ]; then | |
45 | ok | |
46 | else | |
47 | fail | |
48 | fi | |
49 | [ "$out" ] && echo >&2 "$out" | |
50 | else | |
51 | # run config test and abort with nice message if failed | |
52 | # (for actions checking status before action). | |
53 | configtest >/dev/null 2>&1 | |
54 | RETVAL=$? | |
55 | if [ $RETVAL != 0 ]; then | |
56 | show "Checking %s configuration" "Nagios"; fail | |
57 | nls 'Configuration test failed. See details with %s "checkconfig"' $0 | |
58 | exit $RETVAL | |
59 | fi | |
60 | fi | |
61 | } | |
62 | ||
63 | start() { | |
64 | # Check if the service is already running? | |
65 | if [ -f /var/lock/subsys/nagios ]; then | |
66 | msg_already_running "Nagios" | |
67 | return | |
68 | fi | |
69 | ||
70 | checkconfig | |
71 | msg_starting "Nagios" | |
72 | ||
73 | # remove stale cmd pipe (or nagios won't start if it exists) | |
74 | rm -f /var/lib/nagios/rw/nagios.cmd | |
75 | daemon /usr/sbin/nagios -d /etc/nagios/nagios.cfg </dev/null | |
76 | RETVAL=$? | |
77 | if [ $RETVAL -eq 0 ]; then | |
78 | touch /var/lock/subsys/nagios | |
79 | fi | |
80 | } | |
81 | ||
82 | stop() { | |
83 | # Stop daemons. | |
84 | if [ ! -f /var/lock/subsys/nagios ]; then | |
85 | msg_not_running "Nagios" | |
86 | return | |
87 | fi | |
88 | ||
89 | msg_stopping "Nagios" | |
90 | killproc nagios -TERM | |
91 | rm -f /var/lock/subsys/nagios > /dev/null 2>&1 | |
92 | } | |
93 | ||
94 | reload() { | |
95 | if [ ! -f /var/lock/subsys/nagios ]; then | |
96 | msg_not_running "Nagios" | |
97 | RETVAL=7 | |
98 | return | |
99 | fi | |
100 | ||
101 | checkconfig | |
102 | msg_reloading "Nagios" | |
103 | ||
104 | killproc nagios -HUP | |
105 | RETVAL=$? | |
106 | } | |
107 | ||
108 | condrestart() { | |
109 | if [ ! -f /var/lock/subsys/nagios ]; then | |
110 | msg_not_running "Nagios" | |
111 | RETVAL=$1 | |
112 | return | |
113 | fi | |
114 | ||
115 | checkconfig | |
116 | stop | |
117 | start | |
118 | } | |
119 | ||
120 | RETVAL=0 | |
121 | # See how we were called. | |
122 | case "$1" in | |
123 | start) | |
124 | start | |
125 | ;; | |
126 | stop) | |
127 | stop | |
128 | ;; | |
129 | restart) | |
130 | checkconfig | |
131 | stop | |
132 | start | |
133 | ;; | |
134 | try-restart) | |
135 | condrestart 0 | |
136 | ;; | |
137 | reload|force-reload) | |
138 | reload | |
139 | ;; | |
140 | checkconfig|configtest) | |
141 | checkconfig 1 | |
142 | ;; | |
143 | status) | |
144 | status nagios | |
145 | RETVAL=$? | |
146 | ;; | |
147 | *) | |
148 | msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|checkconfig|status}" | |
149 | exit 3 | |
150 | esac | |
151 | ||
152 | exit $RETVAL |