exit 0
fi
+cfg_file=/etc/nagios/nagios.cfg
+
+# check for precache
+precached_object_file=$(awk -F= '/^precached_object_file/{print $2}' $cfg_file)
+
+# configtest itself
+configtest() {
+ /usr/sbin/nagios ${precached_object_file:+-p} -v $cfg_file
+}
+
+# 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
- daemon /usr/sbin/nagios -d /etc/nagios/nagios.cfg </dev/null
+
+ # we're safe to use -x as we did verify config prior startup
+ # precached object file also is created in configtest.
+ daemon /usr/sbin/nagios ${precached_object_file:+-u} -x -d $cfg_file
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
touch /var/lock/subsys/nagios
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"
+
+ # NOTE: precached object file is created in configtest.
+ 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