Created
January 20, 2012 19:52
-
-
Save threetee/1649235 to your computer and use it in GitHub Desktop.
Wrapper to allow runit to send signals to the unicorn master even when its PID changes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
APP=$1 | |
APP_PATH="/srv/${APP}/current" | |
RAILS_ENV=$2 | |
UNICORN_CONFIG="/etc/unicorn/${APP}.rb" | |
UNICORN_PID_FILE="/tmp/unicorn.${APP}.pid" | |
cd $APP_PATH | |
# start Unicorn in the background: | |
bundle exec unicorn -E $RAILS_ENV -c $UNICORN_CONFIG -D | |
# forward signals received in this wrapper to the Unicorn process: | |
for sig in HUP USR1 USR2 QUIT TERM QUIT | |
do | |
trap 'kill -'$sig' $(cat $UNICORN_PID_FILE)' $sig | |
done | |
# loop forever while Unicorn has its pid file | |
while test -e $UNICORN_PID_FILE || test -e $UNICORN_PID_FILE.oldbin | |
do | |
sleep 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment