]> git.pld-linux.org Git - packages/nagios.git/blob - nagios.init
build html documentation
[packages/nagios.git] / nagios.init
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 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
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
37 # configtest itself
38 configtest() {
39         /usr/sbin/nagios ${precached_object_file:+-p} -v $cfg_file
40 }
41
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)
48                 show "Checking %s configuration" "Nagios"; busy
49                 local out
50                 out=`configtest 2>&1`
51                 RETVAL=$?
52                 if [ $RETVAL = 0 ]; then
53                         ok
54                 else
55                         fail
56                 fi
57                 [ "$out" ] && echo >&2 "$out"
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
71 start() {
72         # Check if the service is already running?
73         if [ -f /var/lock/subsys/nagios ]; then
74                 msg_already_running "Nagios"
75                 return
76         fi
77
78         checkconfig
79         msg_starting "Nagios"
80
81         # remove stale cmd pipe (or nagios won't start if it exists)
82         rm -f /var/lib/nagios/rw/nagios.cmd
83
84         # we're safe to use -x as we did verify config prior startup
85         # precached object file also is created in configtest.
86         daemon /usr/sbin/nagios ${precached_object_file:+-u} -x -d $cfg_file
87         RETVAL=$?
88         if [ $RETVAL -eq 0 ]; then
89                 touch /var/lock/subsys/nagios
90         fi
91 }
92
93 stop() {
94         # Stop daemons.
95         if [ ! -f /var/lock/subsys/nagios ]; then
96                 msg_not_running "Nagios"
97                 return
98         fi
99
100         msg_stopping "Nagios"
101         killproc --pidfile $pid_file nagios
102         rm -f /var/lock/subsys/nagios > /dev/null 2>&1
103 }
104
105 reload() {
106         if [ ! -f /var/lock/subsys/nagios ]; then
107                 msg_not_running "Nagios"
108                 RETVAL=7
109                 return
110         fi
111
112         checkconfig
113         msg_reloading "Nagios"
114
115         # NOTE: precached object file is created in configtest.
116         killproc --pidfile $pid_file nagios -HUP
117         RETVAL=$?
118 }
119
120 condrestart() {
121         if [ ! -f /var/lock/subsys/nagios ]; then
122                 msg_not_running "Nagios"
123                 RETVAL=$1
124                 return
125         fi
126
127         checkconfig
128         stop
129         start
130 }
131
132 RETVAL=0
133 # See how we were called.
134 case "$1" in
135   start)
136         start
137         ;;
138   stop)
139         stop
140         ;;
141   restart)
142         checkconfig
143         stop
144         start
145         ;;
146   try-restart)
147         condrestart 0
148         ;;
149   reload|force-reload)
150         reload
151         ;;
152   checkconfig|configtest)
153         checkconfig 1
154         ;;
155   status)
156         status --pidfile $pid_file nagios
157         RETVAL=$?
158         ;;
159 *)
160         msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|checkconfig|status}"
161         exit 3
162 esac
163
164 exit $RETVAL
This page took 0.055106 seconds and 3 git commands to generate.