3 # Nagios Host/service/network monitoring daemon
6 # description: Host/service/network monitoring daemon which uses snort as NIDS
9 # Source function library
10 . /etc/rc.d/init.d/functions
13 . /etc/sysconfig/network
16 [ -f /etc/sysconfig/nagios ] && . /etc/sysconfig/nagios
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"
28 cfg_file=/etc/nagios/nagios.cfg
30 # value to use for $HOME
31 # as pld initscript resets HOME=/tmp, plugins may inherit bad value
32 nagios_home=/usr/lib/nagios
35 precached_object_file=$(awk -F= '/^precached_object_file/{print $2}' $cfg_file)
38 pid_file=$(awk -F= '/^lock_file/{print $2}' $cfg_file)
39 pid_file=${pid_file:-/var/lib/nagios/nagios.pid}
43 /usr/sbin/nagios ${precached_object_file:+-p} -v $cfg_file
46 # wrapper for configtest:
50 if [ $details = 1 ]; then
51 # run config test and display report (status action)
52 show "Checking %s configuration" "Nagios"; busy
56 if [ $RETVAL = 0 ]; then
61 [ "$out" ] && echo >&2 "$out"
63 # run config test and abort with nice message if failed
64 # (for actions checking status before action).
65 configtest >/dev/null 2>&1
67 if [ $RETVAL != 0 ]; then
68 show "Checking %s configuration" "Nagios"; fail
69 nls 'Configuration test failed. See details with %s "checkconfig"' $0
76 # Check if the service is already running?
77 if [ -f /var/lock/subsys/nagios ]; then
78 msg_already_running "Nagios"
85 # remove stale cmd pipe (or nagios won't start if it exists)
86 rm -f /var/lib/nagios/rw/nagios.cmd
88 # we're safe to use -x as we did verify config prior startup
89 # precached object file also is created in configtest.
90 daemon env -i PATH="$PATH" HOME="$nagios_home" /usr/sbin/nagios ${precached_object_file:+-u} -x -d $cfg_file
92 if [ $RETVAL -eq 0 ]; then
93 touch /var/lock/subsys/nagios
99 if [ ! -f /var/lock/subsys/nagios ]; then
100 msg_not_running "Nagios"
104 msg_stopping "Nagios"
105 killproc --pidfile $pid_file nagios
106 rm -f /var/lock/subsys/nagios > /dev/null 2>&1
110 if [ ! -f /var/lock/subsys/nagios ]; then
111 msg_not_running "Nagios"
117 msg_reloading "Nagios"
119 # NOTE: precached object file is created in configtest.
120 killproc --pidfile $pid_file nagios -HUP
125 if [ ! -f /var/lock/subsys/nagios ]; then
126 msg_not_running "Nagios"
137 # See how we were called.
156 checkconfig|configtest)
160 status --pidfile $pid_file nagios
164 msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|checkconfig|status}"