Created
October 6, 2010 02:32
-
-
Save jgelo/612714 to your computer and use it in GitHub Desktop.
RVM w/ multiple rubies + multiple Unicorns
This file contains 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 | |
# | |
# Unicorn application launcher | |
# Load the env config and RVM | |
. /etc/unicorn/$1.conf | |
. /usr/local/rvm/scripts/rvm | |
# Switch to the proper ruby | |
rvm use $RUBY | |
cd $RAILS_ROOT | |
if [[ $RUBY =~ "1.8.7" ]]; then | |
UNICORN=unicorn_rails | |
else | |
UNICORN=unicorn | |
fi | |
# Start unicorn | |
$UNICORN -e "ENV['RAILS_ROOT']='$RAILS_ROOT'" -c /etc/unicorn/unicorn.rb -E $RAILS_ENV -D |
This file contains 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
RUBY=ruby-1.9.2-p0 | |
RAILS_ROOT=/var/www/rails3_example | |
RAILS_ENV=development | |
CMD="/etc/unicorn/app.sh rails3_example" |
This file contains 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
RUBY=ree-1.8.7-2010.02 | |
RAILS_ROOT=/var/www/redmine | |
RAILS_ENV=production | |
CMD="/etc/unicorn/app.sh redmine" |
This file contains 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 | |
# | |
# chkconfig: - 85 15 | |
# description: Unicorn init script for single or multiple unicorn installations. | |
# Expects at least one .conf file in /etc/unicorn | |
# | |
# Modified by jgelo@hoptsolutions.com http://github.com/jgelo | |
# Modified by jay@gooby.org http://github.com/jaygooby | |
# based on http://gist.github.com/308216 by http://github.com/mguterl | |
# | |
# If you call this script without any config parameters, it will attempt to run the | |
# init command for all your unicorn configurations listed in /etc/unicorn/*.conf | |
# | |
# Start all unicorns - | |
# /etc/init.d/unicorn start | |
# | |
# Start a particular unicorn - | |
# /etc/init.d/unicorn start /etc/unicorn/my_app.conf | |
set -e | |
sig () { | |
test -s "$PID" && kill -$1 `cat "$PID"` | |
} | |
oldsig () { | |
test -s "$OLD_PID" && kill -$1 `cat "$OLD_PID"` | |
} | |
cmd () { | |
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 | |
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 | |
} | |
setup () { | |
echo -n "$RAILS_ROOT: " | |
cd $RAILS_ROOT || exit 1 | |
export PID=$RAILS_ROOT/tmp/pids/unicorn.pid | |
export OLD_PID="$PID.oldbin" | |
# CMD is read from the conf file | |
# CMD="/usr/bin/unicorn_rails -c config/unicorn.rb -E $RAILS_ENV -D" | |
} | |
start_stop () { | |
# either run the start/stop/reload/etc command for every config under /etc/unicorn | |
# or just do it for a specific one | |
# $1 contains the start/stop/etc command | |
# $2 if it exists, should be the specific config we want to act on | |
if [ $2 ]; then | |
. $2 | |
setup | |
cmd $1 | |
else | |
for CONFIG in /etc/unicorn/*.conf; do | |
# import the variables | |
. $CONFIG | |
setup | |
# run the start/stop/etc command | |
cmd $1 | |
done | |
fi | |
} | |
ARGS="$1 $2" | |
start_stop $ARGS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment