Package: nginx-common Version: 1.6.2-1 Severity: wishlist Tags: patch Dear Maintainer,
When clustering nginx behind a load balancer it is useful to take the listen socket offline while allowing connected clients to finish their requests with out error. The included patch allows for a graceful-shutdown command that makes this trivial. Both the graceful schedule and the original stop schedule can also be defined in /etc/default/nginx for end user customization. ----- BEGIN PATCH ------- diff -Nru nginx-1.6.2/debian/changelog nginx-1.6.2/debian/changelog --- nginx-1.6.2/debian/changelog 2014-09-17 01:20:11.000000000 -0700 +++ nginx-1.6.2/debian/changelog 2014-09-24 08:50:58.000000000 -0700 @@ -1,3 +1,14 @@ +nginx (1.6.2-1.1) UNRELEASED; urgency=low + + * Non-maintainer upload. + * Signal schedule used by stop command in init script is now configurable + via /etc/defaults/nginx. + * Added graceful-stop command to init script which allows a configurable + schedule to allow connected clients time to finish their request before + the server goes fully offline. + + -- Tyler Riddle <trid...@socialflow.com> Wed, 24 Sep 2014 08:46:41 -0700 + nginx (1.6.2-1) unstable; urgency=high [ Christos Trochalakis ] diff -Nru nginx-1.6.2/debian/nginx-common.nginx.default nginx-1.6.2/debian/nginx-common.nginx.default --- nginx-1.6.2/debian/nginx-common.nginx.default 2014-09-17 01:20:11.000000000 -0700 +++ nginx-1.6.2/debian/nginx-common.nginx.default 2014-09-24 08:50:58.000000000 -0700 @@ -3,3 +3,9 @@ # Set the ulimit variable if you need defaults to change. # Example: ULIMIT="-n 4096" #ULIMIT="-n 4096" + +# Define schedules for quickly and gracefully stopping +# the server; see the start-stop-daemon --retry documentation +# for more information +#STOP_SCHEDULE="TERM/30/KILL/5" +#GRACEFUL_STOP_SCHEDULE="QUIT/20/TERM/5/KILL/5" diff -Nru nginx-1.6.2/debian/nginx-common.nginx.init nginx-1.6.2/debian/nginx-common.nginx.init --- nginx-1.6.2/debian/nginx-common.nginx.init 2014-09-17 01:20:11.000000000 -0700 +++ nginx-1.6.2/debian/nginx-common.nginx.init 2014-09-24 08:50:58.000000000 -0700 @@ -58,8 +58,11 @@ $DAEMON -t $DAEMON_OPTS >/dev/null 2>&1 } +# See http://nginx.org/en/docs/control.html for documentation +# on nginx and signal behavior + # -# Function that stops the daemon/service +# Function that quickly stops the daemon/service # do_stop() { @@ -68,7 +71,33 @@ # 1 if daemon was already stopped # 2 if daemon could not be stopped # other if a failure occurred - start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PID --name $NAME + if [ "$STOP_SCHEDULE" = '' ]; then + STOP_SCHEDULE="TERM/30/KILL/5" + fi + + start-stop-daemon --stop --quiet --retry="$STOP_SCHEDULE" --pidfile $PID --name $NAME + RETVAL="$?" + + sleep 1 + return "$RETVAL" +} + +# +# Function that gives connected clients a chance +# to finish their request before shutdown +# +do_graceful_stop() +{ + # Return + # 0 if daemon has been stopped + # 1 if daemon was already stopped + # 2 if daemon could not be stopped + # other if a failure occurred + if [ "$GRACEFUL_STOP_SCHEDULE" = '' ]; then + GRACEFUL_STOP_SCHEDULE="QUIT/20/TERM/5/KILL/5" + fi + + start-stop-daemon --stop --quiet --retry="$GRACEFUL_STOP_SCHEDULE" --pidfile $PID --name $NAME RETVAL="$?" sleep 1 @@ -140,6 +169,14 @@ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; esac ;; + graceful-stop) + [ "$VERBOSE" != no ] && log_daemon_msg "Gracefully stopping $DESC" "$NAME" + do_graceful_stop + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; restart) log_daemon_msg "Restarting $DESC" "$NAME" @@ -201,7 +238,7 @@ log_end_msg $? ;; *) - echo "Usage: $NAME {start|stop|restart|reload|force-reload|status|configtest|rotate|upgrade}" >&2 + echo "Usage: $NAME {start|stop|graceful-stop|restart|reload|force-reload|status|configtest|rotate|upgrade}" >&2 exit 3 ;; esac -- To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org