Skip to content

Instantly share code, notes, and snippets.

@PatrickTulskie
Created October 19, 2012 13:54
Show Gist options
  • Save PatrickTulskie/3918349 to your computer and use it in GitHub Desktop.
Save PatrickTulskie/3918349 to your computer and use it in GitHub Desktop.
Unicorn init.d Script
#!/bin/sh
set -e
# Setup current directory path
APP_ROOT=/path/to/your/app/current
# Unicorn needs to know to write the PID file here. Adjust this for your own setup.
PID=$APP_ROOT/tmp/pids/unicorn.pid
# GCC settings for Ruby Enterprise Edition
export RUBY_HEAP_MIN_SLOTS=700000
export RUBY_HEAP_FREE_MIN=100000
export RUBY_HEAP_SLOTS_INCREMENT=250000
export RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
export RUBY_GC_MALLOC_LIMIT=50000000
# Go directly to the unicorn_rails path to avoid loading RVM in this script
# For Rails 3 and above, unicorn_rails is not necessary... you can just use unicorn
CMD="/usr/local/rvm/gems/ree-1.8.7-2010.02/bin/unicorn_rails -E production -D -c $APP_ROOT/config/unicorn.rb"
old_pid="$PID.oldbin"
cd $APP_ROOT || exit 1
sig () {
test -s "$PID" && kill -$1 `cat $PID`
}
oldsig () {
test -s $old_pid && kill -$1 `cat $old_pid`
}
case $1 in
start)
sig 0 && echo >&2 "Already running" && exit 0
$CMD
;;
stop)
sig QUIT && exit 0
echo >&2 "Not running"
;;
force-stop)
sig TERM && exit 0
echo >&2 "Not running"
;;
restart|reload)
sig HUP && echo reloaded OK && exit 0
echo >&2 "Couldn't reload, starting '$CMD' instead"
$CMD
;;
upgrade)
sig USR2 && sleep 2 && exit 0
echo >&2 "Couldn't upgrade, starting '$CMD' instead"
$CMD
;;
*)
echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop>"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment