]> git.pld-linux.org Git - packages/nagios.git/blobdiff - nagios.init
- recover dependencies.cfg
[packages/nagios.git] / nagios.init
index d4668051846aab53cf8840729c4a0f9e165734da..cd55aec7aec42713709bdd65a46d6ee5ba36b3b7 100644 (file)
@@ -25,14 +25,39 @@ else
        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() {
@@ -42,8 +67,8 @@ 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
@@ -66,29 +91,30 @@ stop() {
        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
@@ -101,8 +127,7 @@ case "$1" in
        stop
        ;;
   restart)
-       msg_reloading "Nagios"
-       checkconfig || exit && started
+       checkconfig
        stop
        start
        ;;
@@ -112,9 +137,8 @@ case "$1" in
   reload|force-reload)
        reload
        ;;
-  checkconfig|check|configtest)
-       /usr/sbin/nagios -v /etc/nagios/nagios.cfg
-       exit $?
+  checkconfig|configtest)
+       checkconfig 1
        ;;
   status)
        status nagios
This page took 0.087202 seconds and 4 git commands to generate.