Created
April 4, 2011 20:57
-
-
Save troex/902420 to your computer and use it in GitHub Desktop.
Unicorn start/stop/restart script for Debian
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 | |
### BEGIN INIT INFO | |
# Provides: unicorn-kk | |
# Required-Start: $local_fs $remote_fs | |
# Required-Stop: $local_fs $remote_fs | |
# Should-Start: mysql | |
# Should-Stop: mysql | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: unicorn | |
# Description: unicorn | |
### END INIT INFO | |
set -u | |
set -e | |
# Example init script, this can be used with nginx, too, | |
# since nginx and unicorn accept the same signals | |
# Feel free to change any of the following variables for your app: | |
APP_ROOT=/var/www/app/current | |
PID=/var/www/app/shared/pids/unicorn.pid | |
ENV=production | |
CMD="/usr/bin/unicorn_rails -D -E $ENV -c 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 | |
echo >&2 "Started" | |
;; | |
stop) | |
sig QUIT && exit 0 | |
echo >&2 "Not running" | |
;; | |
force-stop) | |
sig TERM && exit 0 | |
echo >&2 "Not running" | |
;; | |
reload) | |
sig HUP && echo reloaded OK && exit 0 | |
echo >&2 "Couldn't reload" | |
#$CMD | |
;; | |
restart) | |
sig USR2 | |
echo >&2 "Starting new master, waiting 10 sec..." | |
sleep 10 | |
echo -n >&2 "Quiting old master... " | |
oldsig QUIT | |
echo >&2 "done" | |
#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|reload|restart|rotate|force-stop>" | |
exit 1 | |
;; | |
esac |
This works great! I needed to add the -H option to sudo to be able to use rvm, though. Here's my /etc/unicorn/wsoacert-ci.conf
:
RAILS_ENV=ci
RAILS_ROOT=/srv/www/wsoacert/current
USER=wsoaref
START_CMD="/home/wsoaref/.rvm/bin/rvm in $RAILS_ROOT do bundle exec unicorn"
UNICORN_CONFIG=$RAILS_ROOT/config/unicorn.rb
Without -H, the HOME
environment variable is not set and RVM complains with Can't find rvm install!
Here's a script that supports RVM properly: https://github.com/knyar/unicorn-rvm-init
Thanks, this looks great.
@patrick-higgins - your code pasted in doesn't contain any "-H"...?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TODO