]> git.pld-linux.org Git - packages/nginx.git/commitdiff
init: add configtest
authorElan Ruusamäe <glen@delfi.ee>
Sun, 3 May 2015 20:02:12 +0000 (23:02 +0300)
committerElan Ruusamäe <glen@delfi.ee>
Sun, 3 May 2015 20:02:12 +0000 (23:02 +0300)
nginx.init

index 2ef3143086b5a0a82e4646f6c30360bbeae37b42..38c75cd9b74a8f830197880f5b8a117bdd7bf7e2 100755 (executable)
@@ -38,9 +38,46 @@ else
        exit 0
 fi
 
+# configtest itself
+# must return non-zero if check failed
+# output is discarded if checkconfig is ran without details
+configtest() {
+       $nginx -t -c $NGINX_CONF_FILE
+}
+
+# wrapper for configtest
+checkconfig() {
+       local details=${1:-0}
+
+       if [ $details = 1 ]; then
+               # run config test and display report (status action)
+               show "Checking %s configuration" "$svname"; 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" "$svname"; fail
+                       nls 'Configuration test failed. See details with %s "checkconfig"' $0
+                       exit $RETVAL
+               fi
+       fi
+}
+
 start() {
        # Check if the service is already running?
        if [ ! -f $lockfile ]; then
+               checkconfig
                msg_starting "$svname"
                daemon $nginx -c $NGINX_CONF_FILE
                RETVAL=$?
@@ -66,6 +103,7 @@ stop() {
 
 reload() {
        if [ -f $lockfile ]; then
+               checkconfig
                msg_reloading "$svname"
                killproc $prog -HUP
                RETVAL=$?
@@ -82,6 +120,7 @@ condrestart() {
                return
        fi
 
+       checkconfig
        stop
        start
 }
@@ -96,6 +135,7 @@ case "$1" in
        stop
        ;;
   restart)
+       checkconfig
        stop
        start
        ;;
@@ -105,12 +145,15 @@ case "$1" in
   reload|force-reload|graceful)
        reload
        ;;
+  checkconfig|configtest)
+       checkconfig 1
+       ;;
   status)
        status $prog
        RETVAL=$?
        ;;
   *)
-       msg_usage "$0 {start|stop|restart|reload|force-reload|graceful|status}"
+       msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|graceful|checkconfig|status}"
        exit 3
        ;;
 esac
This page took 0.129307 seconds and 4 git commands to generate.