exit 0
fi
+# configtest itself
+configtest() {
+ /usr/sbin/nagios -v /etc/nagios/nagios.cfg 2>&1
+ return $?
+}
+
+# wrapper for configtest:
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
+ 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
}
start() {
return
fi
+ checkconfig
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
rm -f /var/lock/subsys/nagios > /dev/null 2>&1
}
-condrestart() {
+reload() {
if [ ! -f /var/lock/subsys/nagios ]; then
msg_not_running "Nagios"
- RETVAL=$1
+ RETVAL=7
return
fi
- stop
- start
+ checkconfig
+ msg_reloading "Nagios"
+
+ killproc nagios -HUP
+ RETVAL=$?
}
-reload() {
+condrestart() {
if [ ! -f /var/lock/subsys/nagios ]; then
msg_not_running "Nagios"
- RETVAL=7
+ RETVAL=$1
return
fi
- msg_reloading "Nagios"
- checkconfig || exit
-
- killproc nagios -HUP
- RETVAL=$?
+ checkconfig
+ stop
+ start
}
RETVAL=0
stop
;;
restart)
- msg_reloading "Nagios"
- checkconfig || exit && started
+ checkconfig
stop
start
;;
reload|force-reload)
reload
;;
- checkconfig|check|configtest)
- /usr/sbin/nagios -v /etc/nagios/nagios.cfg
- exit $?
+ checkconfig|configtest)
+ checkconfig 1
;;
status)
status nagios