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
31 precached_object_file=$(awk -F= '/^precached_object_file/{print $2}' $cfg_file)
34 pid_file=$(awk -F= '/^lock_file/{print $2}' $cfg_file)
35 pid_file=${pid_file:-/var/lib/nagios/nagios.pid}
39 /usr/sbin/nagios ${precached_object_file:+-p} -v $cfg_file
42 # wrapper for configtest:
46 if [ $details = 1 ]; then
47 # run config test and display report (status action)
48 show "Checking %s configuration" "Nagios"; busy
52 if [ $RETVAL = 0 ]; then
57 [ "$out" ] && echo >&2 "$out"
59 # run config test and abort with nice message if failed
60 # (for actions checking status before action).
61 configtest >/dev/null 2>&1
63 if [ $RETVAL != 0 ]; then
64 show "Checking %s configuration" "Nagios"; fail
65 nls 'Configuration test failed. See details with %s "checkconfig"' $0
72 # Check if the service is already running?
73 if [ -f /var/lock/subsys/nagios ]; then
74 msg_already_running "Nagios"
81 # remove stale cmd pipe (or nagios won't start if it exists)
82 rm -f /var/lib/nagios/rw/nagios.cmd
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
88 if [ $RETVAL -eq 0 ]; then
89 touch /var/lock/subsys/nagios
95 if [ ! -f /var/lock/subsys/nagios ]; then
96 msg_not_running "Nagios"
100 msg_stopping "Nagios"
101 killproc --pidfile $pid_file nagios
102 rm -f /var/lock/subsys/nagios > /dev/null 2>&1
106 if [ ! -f /var/lock/subsys/nagios ]; then
107 msg_not_running "Nagios"
113 msg_reloading "Nagios"
115 # NOTE: precached object file is created in configtest.
116 killproc --pidfile $pid_file nagios -HUP
121 if [ ! -f /var/lock/subsys/nagios ]; then
122 msg_not_running "Nagios"
133 # See how we were called.
152 checkconfig|configtest)
156 status --pidfile $pid_file nagios
160 msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|checkconfig|status}"