[DRE-commits] [unicorn] 03/03: Move upgrade code to init script

Hleb Valoshka tsfgnu-guest at moszumanska.debian.org
Mon Nov 2 13:06:42 UTC 2015


This is an automated email from the git hooks/post-receive script.

tsfgnu-guest pushed a commit to branch master
in repository unicorn.

commit d5075324cc2c008a13c17a34a1c3bdc45b462a53
Author: Hleb Valoshka <375gnu at gmail.com>
Date:   Wed Oct 7 16:18:18 2015 +0300

    Move upgrade code to init script
---
 debian/unicorn.init     | 28 ++++++++++++++++++++++++++-
 debian/unicorn.postinst | 51 ++++---------------------------------------------
 2 files changed, 31 insertions(+), 48 deletions(-)

diff --git a/debian/unicorn.init b/debian/unicorn.init
index 61c87cd..ffaae7d 100644
--- a/debian/unicorn.init
+++ b/debian/unicorn.init
@@ -24,9 +24,11 @@ fi
 
 DAEMON=/usr/bin/unicorn
 PID=${PID-/run/unicorn.pid}
+OLD_PID="${PID}.oldbin"
+TIMEOUT=${TIMEOUT-60}
 
 run_by_init() {
-    ([ "${previous-}" ] && [ "${runlevel-}" ]) || [ "${runlevel-}" = S ]
+  ([ "${previous-}" ] && [ "${runlevel-}" ]) || [ "${runlevel-}" = S ]
 }
 
 exit_with_message() {
@@ -42,6 +44,14 @@ check_config_rb() {
   fi
 }
 
+sig() {
+  test -s $PID && kill -$1 `cat $PID`
+}
+
+oldsig() {
+  test -s $OLD_PID && kill -$1 `cat $OLD_PID`
+}
+
 set -u
 
 case "$1" in
@@ -97,6 +107,22 @@ case "$1" in
           log_end_msg 1 || true
         fi
         ;;
+  upgrade)
+        log_daemon_msg "Trying to upgrade running server" || true
+        if sig USR2 && sleep 2 && sig 0 && oldsig QUIT ; then
+          n=$TIMEOUT
+          while test -s $OLD_PID && test $n -ge 0 ; do
+            printf '.' && sleep 1 && n=`expr $n - 1`
+          done
+
+          if test $n -lt 0 && test -s $OLD_PID; then
+            log_daemon_msg "$OLD_PID still exists after $TIMEOUT seconds. Killing and starting new." || true
+            sig KILL || true
+            oldsig KILL || true
+            invoke-rc.d unicorn start || exit $?
+          fi
+        fi
+        ;;
   status)
         status_of_proc -p $PID $DAEMON $NAME && exit 0 || exit $?
         ;;
diff --git a/debian/unicorn.postinst b/debian/unicorn.postinst
index 18d4cd7..4874386 100644
--- a/debian/unicorn.postinst
+++ b/debian/unicorn.postinst
@@ -6,57 +6,14 @@ if [ $1 != "configure" ] ; then
   exit 0
 fi
 
-if [ -f /etc/default/unicorn ]; then
-  . /etc/default/unicorn
-fi
-
-TIMEOUT=${TIMEOUT-60}
-PID=${PID-/run/unicorn.pid}
-OLD_PID="${PID}.oldbin"
-
-invoke() {
-  if [ -x "$(which invoke-rc.d)" ]; then
-    invoke-rc.d $1 $2
-  else
-    /etc/init.d/$1 $2
-  fi
-}
-
 running() {
-  invoke $1 status >/dev/null 2>&1
-}
-
-sig() {
-  test -s $PID && kill -$1 `cat $PID`
-}
-
-oldsig() {
-  test -s $OLD_PID && kill -$1 `cat $OLD_PID`
-}
-
-upgrade() {
-  echo "Trying to upgrade running server"
-  if sig USR2 && sleep 2 && sig 0 && oldsig QUIT ; then
-    n=$TIMEOUT
-    while test -s $OLD_PID && test $n -ge 0 ; do
-      printf '.' && sleep 1 && n=`expr $n - 1`
-    done
-
-    if test $n -lt 0 && test -s $OLD_PID; then
-      echo "$OLD_PID still exists after $TIMEOUT seconds. Killing and starting new."
-      sig KILL || true
-      oldsig KILL || true
-      invoke unicorn start || exit $?
-    fi
-  fi
+  invoke-rc.d $1 status >/dev/null 2>&1
 }
 
 if [ -x /etc/init.d/unicorn ]; then
-    if running unicorn; then
-      upgrade
-    else
-      invoke unicorn start || exit $?
-    fi
+  if running unicorn; then
+    invoke-rc.d unicorn upgrade
+  fi
 fi
 
 #DEBHELPER#

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/unicorn.git



More information about the Pkg-ruby-extras-commits mailing list