#!/bin/sh
#
-# nagios Host/service/network monitoring daemon
+# Nagios Host/service/network monitoring daemon
#
-# chkconfig: 345 50 50
+# chkconfig: 345 85 24
# description: Host/service/network monitoring daemon which uses snort as NIDS
#
# Check that networking is up.
if is_yes "${NETWORKING}"; then
- if [ ! -f /var/lock/subsys/network ]; then
- # nls "ERROR: Networking is down. %s can't be run." <service>
- msg_network_down nagios
- exit 1
- fi
+ if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
+ msg_network_down Nagios
+ exit 1
+ fi
else
- exit 0
+ exit 0
fi
-# See how we were called.
-case "$1" in
- start)
+checkconfig() {
+ /usr/sbin/nagios -v /etc/nagios/nagios.cfg > /dev/null
+ rc=$?
+ if [ $rc -gt 0 ]; then
+ fail
+ nls 'The configuration is broken. See details with %s "checkconfig"' /etc/rc.d/init.d/nagios
+ fi
+ return $rc
+}
+
+start() {
# Check if the service is already running?
- if [ ! -f /var/lock/subsys/nagios ]; then
- msg_starting nagios
- # remove stale cmd pipe (or nagios won't start if it exists)
- rm -f /var/lib/nagios/rw/nagios.cmd
- daemon nagios -d /etc/nagios/nagios.cfg </dev/null
- RETVAL=$?
+ if [ ! -f /var/lock/subsys/nagios ]; then
+ msg_starting Nagios
+ checkconfig || exit
+
+ # remove stale cmd pipe (or nagios won't start if it exists)
+ rm -f /var/lib/nagios/rw/nagios.cmd
+ daemon /usr/sbin/nagios -d /etc/nagios/nagios.cfg </dev/null
+ RETVAL=$?
if [ $RETVAL -eq 0 ]; then
touch /var/lock/subsys/nagios
- chgrp http /var/lib/nagios/rw/nagios.cmd
fi
else
- msg_already_running nagios
- exit 1
+ msg_already_running Nagios
fi
- ;;
- stop)
- # Stop daemons.
+}
+
+stop() {
+ # Stop daemons.
if [ -f /var/lock/subsys/nagios ]; then
- msg_stopping nagios
- killproc nagios -TERM
- rm -f /var/lock/subsys/nagios > /dev/null 2>&1
- else
- msg_not_running nagios
- exit 1
+ msg_stopping Nagios
+ killproc nagios -TERM
+ rm -f /var/lock/subsys/nagios > /dev/null 2>&1
+ else
+ msg_not_running Nagios
fi
+}
+
+RETVAL=0
+# See how we were called.
+case "$1" in
+start)
+ start
;;
- status)
- status nagios
- RETVAL=$?
+stop)
+ stop
+ ;;
+checkconfig|check|configtest)
+ /usr/sbin/nagios -v /etc/nagios/nagios.cfg
+ exit $?
+ ;;
+reload|force-reload)
+ if [ -f /var/lock/subsys/nagios ]; then
+ msg_reloading Nagios
+ checkconfig || exit
+
+ killproc nagios -HUP
+ RETVAL=$?
+ else
+ msg_not_running Nagios
+ exit 7
+ fi
;;
- restart|reload)
- $0 stop
- $0 start
+restart)
+ msg_reloading Nagios
+ checkconfig || exit && started
+ stop
+ start
;;
- *)
- msg_usage "$0 {start|stop|restart|status}"
- exit 1
+status)
+ status nagios
+ exit $?
;;
+*)
+ msg_usage "$0 {start|stop|restart|reload|force-reload|status|checkconfig}"
+ exit 3
esac
exit $RETVAL
-