]>
Commit | Line | Data |
---|---|---|
96018fcf TO |
1 | #!/bin/sh |
2 | # | |
47010e3e | 3 | # Nagios Host/service/network monitoring daemon |
96018fcf | 4 | # |
20cccccd | 5 | # chkconfig: 345 85 24 |
96018fcf TO |
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 | |
9405ddf7 | 20 | if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then |
1056cd95 | 21 | msg_network_down "Nagios" |
043169b2 | 22 | exit 1 |
23 | fi | |
96018fcf | 24 | else |
043169b2 | 25 | exit 0 |
96018fcf TO |
26 | fi |
27 | ||
19cc8e59 ER |
28 | cfg_file=/etc/nagios/nagios.cfg |
29 | ||
30 | # check for precache | |
31 | precached_object_file=$(awk -F= '/^precached_object_file/{print $2}' $cfg_file) | |
32 | ||
d12528d9 ER |
33 | # nagios pid file |
34 | pid_file=$(awk -F= '/^lock_file/{print $2}' $cfg_file) | |
35 | pid_file=${pid_file:-/var/lib/nagios/nagios.pid} | |
36 | ||
d5757369 ER |
37 | # configtest itself |
38 | configtest() { | |
19cc8e59 | 39 | /usr/sbin/nagios ${precached_object_file:+-p} -v $cfg_file |
20bd359d AG |
40 | } |
41 | ||
d5757369 ER |
42 | # wrapper for configtest: |
43 | checkconfig() { | |
44 | local details=${1:-0} | |
45 | ||
46 | if [ $details = 1 ]; then | |
47 | # run config test and display report (status action) | |
0fa2be77 ER |
48 | show "Checking %s configuration" "Nagios"; busy |
49 | local out | |
50 | out=`configtest 2>&1` | |
d5757369 | 51 | RETVAL=$? |
0fa2be77 ER |
52 | if [ $RETVAL = 0 ]; then |
53 | ok | |
54 | else | |
55 | fail | |
0fa2be77 | 56 | fi |
cd6567d2 | 57 | [ "$out" ] && echo >&2 "$out" |
d5757369 ER |
58 | else |
59 | # run config test and abort with nice message if failed | |
60 | # (for actions checking status before action). | |
61 | configtest >/dev/null 2>&1 | |
62 | RETVAL=$? | |
63 | if [ $RETVAL != 0 ]; then | |
64 | show "Checking %s configuration" "Nagios"; fail | |
65 | nls 'Configuration test failed. See details with %s "checkconfig"' $0 | |
66 | exit $RETVAL | |
67 | fi | |
68 | fi | |
69 | } | |
70 | ||
568ca34a | 71 | start() { |
96018fcf | 72 | # Check if the service is already running? |
1056cd95 ER |
73 | if [ -f /var/lock/subsys/nagios ]; then |
74 | msg_already_running "Nagios" | |
75 | return | |
76 | fi | |
77 | ||
d5757369 | 78 | checkconfig |
1056cd95 | 79 | msg_starting "Nagios" |
1056cd95 ER |
80 | |
81 | # remove stale cmd pipe (or nagios won't start if it exists) | |
82 | rm -f /var/lib/nagios/rw/nagios.cmd | |
19cc8e59 ER |
83 | |
84 | # we're safe to use -x as we did verify config prior startup | |
85 | # precached object file also is created in configtest. | |
4144a1ff | 86 | daemon /usr/sbin/nagios ${precached_object_file:+-u} -x -d $cfg_file |
1056cd95 ER |
87 | RETVAL=$? |
88 | if [ $RETVAL -eq 0 ]; then | |
89 | touch /var/lock/subsys/nagios | |
96018fcf | 90 | fi |
568ca34a ER |
91 | } |
92 | ||
93 | stop() { | |
043169b2 | 94 | # Stop daemons. |
1056cd95 ER |
95 | if [ ! -f /var/lock/subsys/nagios ]; then |
96 | msg_not_running "Nagios" | |
97 | return | |
96018fcf | 98 | fi |
1056cd95 ER |
99 | |
100 | msg_stopping "Nagios" | |
d12528d9 | 101 | killproc --pidfile $pid_file nagios |
1056cd95 ER |
102 | rm -f /var/lock/subsys/nagios > /dev/null 2>&1 |
103 | } | |
104 | ||
cd6567d2 | 105 | reload() { |
1056cd95 ER |
106 | if [ ! -f /var/lock/subsys/nagios ]; then |
107 | msg_not_running "Nagios" | |
cd6567d2 | 108 | RETVAL=7 |
1056cd95 ER |
109 | return |
110 | fi | |
111 | ||
d5757369 | 112 | checkconfig |
cd6567d2 ER |
113 | msg_reloading "Nagios" |
114 | ||
19cc8e59 | 115 | # NOTE: precached object file is created in configtest. |
d12528d9 | 116 | killproc --pidfile $pid_file nagios -HUP |
cd6567d2 | 117 | RETVAL=$? |
1056cd95 ER |
118 | } |
119 | ||
cd6567d2 | 120 | condrestart() { |
1056cd95 ER |
121 | if [ ! -f /var/lock/subsys/nagios ]; then |
122 | msg_not_running "Nagios" | |
cd6567d2 | 123 | RETVAL=$1 |
1056cd95 ER |
124 | return |
125 | fi | |
126 | ||
d5757369 | 127 | checkconfig |
cd6567d2 ER |
128 | stop |
129 | start | |
568ca34a ER |
130 | } |
131 | ||
132 | RETVAL=0 | |
133 | # See how we were called. | |
134 | case "$1" in | |
1056cd95 | 135 | start) |
568ca34a | 136 | start |
96018fcf | 137 | ;; |
1056cd95 | 138 | stop) |
568ca34a | 139 | stop |
96018fcf | 140 | ;; |
1056cd95 | 141 | restart) |
d5757369 | 142 | checkconfig |
568ca34a ER |
143 | stop |
144 | start | |
145 | ;; | |
1056cd95 ER |
146 | try-restart) |
147 | condrestart 0 | |
148 | ;; | |
149 | reload|force-reload) | |
150 | reload | |
151 | ;; | |
cd6567d2 | 152 | checkconfig|configtest) |
d5757369 | 153 | checkconfig 1 |
96018fcf | 154 | ;; |
1056cd95 | 155 | status) |
d12528d9 | 156 | status --pidfile $pid_file nagios |
1056cd95 ER |
157 | RETVAL=$? |
158 | ;; | |
62e2d388 | 159 | *) |
1056cd95 | 160 | msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|checkconfig|status}" |
64d31ef5 | 161 | exit 3 |
96018fcf TO |
162 | esac |
163 | ||
164 | exit $RETVAL |