Skip to content

Instantly share code, notes, and snippets.

@timothyklim
Forked from threetee/unicorn_wrapper.sh
Created June 3, 2013 15:54
Show Gist options
  • Select an option

  • Save timothyklim/5699149 to your computer and use it in GitHub Desktop.

Select an option

Save timothyklim/5699149 to your computer and use it in GitHub Desktop.
#!/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