Created
August 13, 2013 06:37
-
-
Save paceline/6218422 to your computer and use it in GitHub Desktop.
Using unicorn with a RVM-based Ruby installation can be a little bit tricky. Here's a init.d script that worked for me.
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/bash | |
### BEGIN INIT INFO | |
# Provides: tuvocabulario.com | |
# 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 tuvocabulario.com at boot time. | |
### END INIT INFO | |
set -u | |
set -e | |
# Change these to match your app: | |
APP_NAME=tuvocabulario.com | |
APP_ROOT="/var/www/$APP_NAME/current" | |
PID="$APP_ROOT/tmp/pids/unicorn.pid" | |
ENV=production | |
GEM_HOME="/usr/local/rvm/gems/ruby-1.8.7-p302" | |
UNICORN_OPTS="-D -E $ENV -c $APP_ROOT/config/unicorn.rb" | |
SET_PATH="cd $APP_ROOT; rvm 1.8.7; export GEM_HOME=$GEM_HOME" | |
CMD="$SET_PATH; $GEM_HOME/bin/unicorn_rails $UNICORN_OPTS" | |
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-help} in | |
start) | |
sig 0 && echo >&2 "Already running" && exit 0 | |
su - ulf -c "$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" | |
su - ulf -c "$CMD" | |
;; | |
upgrade) | |
sig USR2 && exit 0 | |
echo >&2 "Couldn't upgrade, starting '$CMD' instead" | |
su - ulf -c "$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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment