summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-06-10 17:12:37 -0700
committerEric Wong <normalperson@yhbt.net>2010-06-10 17:13:17 -0700
commit264337bcdb77252404fcef62be1efc5a125d781f (patch)
tree67048d05fcf934c420a81cbba20a9f876d9952ea
parente8a3abc038c6a282a1e9943039c9e46c27720928 (diff)
This makes the user (sysadmin in this case) more aware if the
upgrade fails or doesn't work as intended.  This change could be
more useful for Rainbows! with its long-running responses.
-rw-r--r--examples/init.sh18
1 files changed, 17 insertions, 1 deletions
diff --git a/examples/init.sh b/examples/init.sh
index e483976..1f0e035 100644
--- a/examples/init.sh
+++ b/examples/init.sh
@@ -4,6 +4,7 @@ set -e
 # since nginx and unicorn accept the same signals
 
 # Feel free to change any of the following variables for your app:
+TIMEOUT=${TIMEOUT-60}
 APP_ROOT=/home/x/my_app/current
 PID=$APP_ROOT/tmp/pids/unicorn.pid
 CMD="/usr/bin/unicorn -D -c $APP_ROOT/config/unicorn.rb"
@@ -44,7 +45,22 @@ restart|reload)
         $CMD
         ;;
 upgrade)
-        sig USR2 && sleep 2 && sig 0 && oldsig QUIT && exit 0
+        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=$(( $n - 1 ))
+                done
+                echo
+
+                if test $n -lt 0 && test -s $old_pid
+                then
+                        echo >&2 "$old_pid still exists after $TIMEOUT seconds"
+                        exit 1
+                fi
+                exit 0
+        fi
         echo >&2 "Couldn't upgrade, starting '$CMD' instead"
         $CMD
         ;;