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