From 264337bcdb77252404fcef62be1efc5a125d781f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 10 Jun 2010 17:12:37 -0700 Subject: examples/init: "upgrade" task waits for completion 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. --- examples/init.sh | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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 ;; -- cgit v1.2.3-24-ge0c7