Permalink
Browse files

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.
  • Loading branch information...
1 parent e8a3abc commit 264337bcdb77252404fcef62be1efc5a125d781f Eric Wong committed Jun 11, 2010
Showing with 17 additions and 1 deletion.
  1. +17 −1 examples/init.sh
View
18 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
;;

0 comments on commit 264337b

Please sign in to comment.