Package: nginx
Version: 1.9.1-1

Many actions offered by the initscript do not preserve or give the
proper return code. One notable example is the "configtest" that always
returns 0 even when problems are detected:

 echo "invalid" >> /etc/nging/nginx.conf
 service nginx configtest
 echo $?

Should return 1 but returns 0 instead.

The attached patch makes the initscript preserve the return code for all
supported actions.

Regards,
Simon
--- nginx-common.nginx.init.orig	2015-06-12 16:01:06.000000000 -0400
+++ nginx-common.nginx.init	2015-06-12 16:02:48.438224547 -0400
@@ -127,19 +127,19 @@
 
 case "$1" in
 	start)
-		[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
+		log_daemon_msg "Starting $DESC" "$NAME"
 		do_start
 		case "$?" in
-			0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
-			2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+			0|1) log_end_msg 0 ;;
+			2)   log_end_msg 1 ;;
 		esac
 		;;
 	stop)
-		[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
+		log_daemon_msg "Stopping $DESC" "$NAME"
 		do_stop
 		case "$?" in
-			0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
-			2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+			0|1) log_end_msg 0 ;;
+			2)   log_end_msg 1 ;;
 		esac
 		;;
 	restart)
@@ -148,7 +148,7 @@
 		# Check configuration before stopping nginx
 		if ! test_nginx_config; then
 			log_end_msg 1 # Configuration error
-			exit 0
+			exit $?
 		fi
 
 		do_stop
@@ -178,7 +178,7 @@
 		# to the administrator.
 		if ! test_nginx_config; then
 			log_end_msg 1 # Configuration error
-			exit 0
+			exit $?
 		fi
 
 		do_reload
@@ -190,12 +190,12 @@
 		log_end_msg $?
 		;;
 	status)
-		status_of_proc -p $PID "$DAEMON" "$NAME" && exit 0 || exit $?
+		status_of_proc -p $PID "$DAEMON" "$NAME"
 		;;
 	upgrade)
 		log_daemon_msg "Upgrading binary" "$NAME"
 		do_upgrade
-		log_end_msg 0
+		log_end_msg $?
 		;;
 	rotate)
 		log_daemon_msg "Re-opening $DESC log files" "$NAME"
@@ -207,5 +207,3 @@
 		exit 3
 		;;
 esac
-
-:

Reply via email to