#!/bin/sh
#
-# nagios Host/service/network monitoring daemon
+# Nagios Host/service/network monitoring daemon
#
# 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 -a "$1" != stop -a "$1" != status ]; then
- msg_network_down nagios
+ msg_network_down "Nagios"
exit 1
fi
else
exit 0
fi
+# configtest itself
+configtest() {
+ /usr/sbin/nagios -v /etc/nagios/nagios.cfg 2>&1
+ return $?
+}
+
+# wrapper for configtest:
checkconfig() {
- res=`/usr/sbin/nagios -v /etc/nagios/nagios.cfg`
- rc=$?
- if [ $rc -gt 0 ]; then
- fail
- nls 'The configuration is broken. See details with %s "checkconfig"' $0
+ local details=${1:-0}
+
+ if [ $details = 1 ]; then
+ # run config test and display report (status action)
+ show "Checking %s configuration" "Nagios"; busy
+ local out
+ out=`configtest 2>&1`
+ RETVAL=$?
+ if [ $RETVAL = 0 ]; then
+ ok
+ else
+ fail
+ fi
+ [ "$out" ] && echo >&2 "$out"
+ else
+ # run config test and abort with nice message if failed
+ # (for actions checking status before action).
+ configtest >/dev/null 2>&1
+ RETVAL=$?
+ if [ $RETVAL != 0 ]; then
+ show "Checking %s configuration" "Nagios"; fail
+ nls 'Configuration test failed. See details with %s "checkconfig"' $0
+ exit $RETVAL
+ fi
fi
- return $rc
}
-RETVAL=0
-# See how we were called.
-case "$1" in
-start)
+start() {
# Check if the service is already running?
- if [ ! -f /var/lock/subsys/nagios ]; then
- msg_starting nagios
- checkconfig || exit
+ if [ -f /var/lock/subsys/nagios ]; then
+ msg_already_running "Nagios"
+ return
+ fi
- # 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
+ checkconfig
+ msg_starting "Nagios"
- if [ -e /var/lib/nagios/rw/nagios.cmd ]; then
- chgrp http /var/lib/nagios/rw/nagios.cmd
- fi
- fi
- else
- msg_already_running nagios
+ # 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
fi
- ;;
-stop)
+}
+
+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
+ if [ ! -f /var/lock/subsys/nagios ]; then
+ msg_not_running "Nagios"
+ return
fi
+
+ msg_stopping "Nagios"
+ killproc nagios -TERM
+ rm -f /var/lock/subsys/nagios > /dev/null 2>&1
+}
+
+reload() {
+ if [ ! -f /var/lock/subsys/nagios ]; then
+ msg_not_running "Nagios"
+ RETVAL=7
+ return
+ fi
+
+ checkconfig
+ msg_reloading "Nagios"
+
+ killproc nagios -HUP
+ RETVAL=$?
+}
+
+condrestart() {
+ if [ ! -f /var/lock/subsys/nagios ]; then
+ msg_not_running "Nagios"
+ RETVAL=$1
+ return
+ fi
+
+ checkconfig
+ stop
+ start
+}
+
+RETVAL=0
+# See how we were called.
+case "$1" in
+ start)
+ start
;;
-status)
- status nagios
- exit $?
+ stop)
+ stop
;;
-checkconfig|check)
- /usr/sbin/nagios -v /etc/nagios/nagios.cfg
- exit $?
+ restart)
+ checkconfig
+ stop
+ start
;;
-reload|force-reload)
- if [ -f /var/lock/subsys/nagios ]; then
- msg_reloading nagios
- checkconfig || exit
-
- killproc nagios -HUP
- RETVAL=$?
- else
- msg_not_running nagios >&2
- exit 7
- fi
+ try-restart)
+ condrestart 0
;;
-restart)
- msg_reloading nagios
- checkconfig || exit && started
- $0 stop
- $0 start
- exit $?
+ reload|force-reload)
+ reload
+ ;;
+ checkconfig|configtest)
+ checkconfig 1
+ ;;
+ status)
+ status nagios
+ RETVAL=$?
;;
*)
- msg_usage "$0 {start|stop|restart|reload|force-reload|status|checkconfig}"
+ msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|checkconfig|status}"
exit 3
esac