From 27d3b1951c3481d642d5269f685909c9e4911956 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Elan=20Ruusam=C3=A4e?= Date: Sun, 3 May 2015 23:32:44 +0300 Subject: [PATCH] add upgrade target to initscript to gracefully upgrade binary --- nginx.init | 25 ++++++++++++++++++++++++- nginx.spec | 8 ++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/nginx.init b/nginx.init index ad6d1dc..16da7a9 100755 --- a/nginx.init +++ b/nginx.init @@ -123,6 +123,26 @@ condrestart() { start } +# Upgrade the binary with no downtime. +# http://nginx.org/en/docs/control.html#upgrade +# TODO: handle revert back on failed upgrade +upgrade() { + local oldbin_pidfile="${pidfile}.oldbin" + + checkconfig + show "Upgrading $svname" + killproc -p $pidfile $prog -USR2 + RETVAL=$? + sleep 1 + if [ -f $oldbin_pidfile ] && [ -f $pidfile ]; then + show "Upgrade: stopping old process" + killproc -p $oldbin_pidfile $prog -QUIT + return 0 + else + return 1 + fi +} + RETVAL=0 # See how we were called. case "$1" in @@ -140,9 +160,12 @@ case "$1" in try-restart) condrestart 0 ;; - reload|force-reload|graceful) + reload|graceful) reload ;; + force-reload|upgrade) + upgrade + ;; checkconfig|configtest) checkconfig 1 ;; diff --git a/nginx.spec b/nginx.spec index d66d472..7a39ec6 100644 --- a/nginx.spec +++ b/nginx.spec @@ -473,7 +473,7 @@ for a in access.log error.log; do done /sbin/chkconfig --add %{name}-standard %systemd_post %{name}-standard.service -%service %{name}-standard restart +%service %{name}-standard force-reload echo 'NOTE: this nginx daemon is using "/etc/nginx/nginx-standard.conf" as config.' if ! [ -L /etc/systemd/system/nginx.service ] ; then ln -s %{systemdunitdir}/%{name}-standard.service /etc/systemd/system/nginx.service || : @@ -490,7 +490,7 @@ for a in access.log error.log; do done /sbin/chkconfig --add %{name}-light %systemd_post %{name}-light.service -%service %{name}-light restart +%service %{name}-light force-reload echo 'NOTE: this nginx daemon is using "/etc/nginx/nginx-light.conf" as config' %post perl @@ -504,7 +504,7 @@ for a in access.log error.log; do done /sbin/chkconfig --add %{name}-perl %systemd_post %{name}-perl.service -%service %{name}-perl restart +%service %{name}-perl force-reload echo 'NOTE: this nginx daemon is using "/etc/nginx/nginx-perl.conf" as config' %post mail @@ -518,7 +518,7 @@ for a in access.log error.log; do done /sbin/chkconfig --add %{name}-mail %systemd_post %{name}-mail.service -%service %{name}-mail restart +%service %{name}-mail force-reload echo 'NOTE: this nginx daemon is using "/etc/nginx/nginx-mail.conf" as config' %preun standard -- 2.44.0