Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@nlevchuk
Forked from vdv/unicorn
Created March 27, 2012 09:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nlevchuk/2214505 to your computer and use it in GitHub Desktop.
Save nlevchuk/2214505 to your computer and use it in GitHub Desktop.
unicorn init.d script with rvm on ubuntu 11.04
#!/bin/bash
### BEGIN INIT INFO
# Provides: APPLICATION
# Required-Start: $all
# Required-Stop: $network $local_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start the APPLICATION unicorns at boot
# Description: Enable APPLICATION at boot time.
### END INIT INFO
#
# Use this as a basis for your own Unicorn init script.
# Change APPLICATION to match your app.
# Make sure that all paths are correct.
#set -u
set -e
# Change these to match your app:
RAILS_ROOT="/home/www/my_server"
PID="$RAILS_ROOT/tmp/pids/unicorn.pid"
OLD_PID="$PID.oldpid"
ENV=production
UNICORN_OPTS="-D -E $ENV -c $RAILS_ROOT/config/unicorn.conf"
CMD="/home/www/my_server/unicorn_rails_wrapper $UNICORN_OPTS"
cd $RAILS_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
echo "Starting"
$CMD
;;
stop)
sig QUIT && echo "Stopping" && exit 0
echo >&2 "Not running"
;;
force-stop)
sig TERM && echo "Forcing a stop" && exit 0
echo >&2 "Not running"
;;
restart|reload)
#sig USR2 && sleep 5 && oldsig QUIT && echo "Killing old master" `cat $OLD_PID` && exit 0
sig USR2 && echo reloaded OK && exit 0
echo >&2 "Couldn't reload, starting '$CMD' instead"
$CMD
;;
upgrade)
sig USR2 && echo Upgraded && exit 0
echo >&2 "Couldn't upgrade, starting '$CMD' instead"
$CMD
;;
rotate)
sig USR1 && echo rotated logs OK && exit 0
echo >&2 "Couldn't rotate logs" && exit 1
;;
*)
echo >&2 "Usage: $0 <start|stop|restart|upgrade|rotate|force-stop>"
exit 1
;;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment