diff options
-rw-r--r-- | examples/init.sh | 18 |
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 ;; |