Skip to content

Instantly share code, notes, and snippets.

@vdv
Created January 30, 2012 15:18
Show Gist options
  • Save vdv/1704927 to your computer and use it in GitHub Desktop.
Save vdv/1704927 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
;;
esac
@Zane5
Copy link

Zane5 commented Aug 14, 2012

what is about unicorn_rails_wrapper ? thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment