We recently migrated some of our Rails apps together in the cloud and found ourselves with a bit of a quandary - how to host a mix of current (Rails 3.x) and legacy (Rails < 3.x) apps on the same server while being able to monitor and control them all with one tool?
This would have been fairly straightforward if all our apps used the same version of Ruby and gems, however, we're using MRI 1.9.2 for the Rails 3.x apps and REE 1.8.7 for the legacy apps.
There are a couple different ways to handle this scenario, but here's what we ended up using to make it all play nice -
- RVM. This tool makes managing multiple ruby environments a breeze and is almost a must have for developing Rails apps with different version and gem requirements.
- NGINX + Unicorn. A mythical beast of an app server and an efficient, lightweight HTTP/proxy server that work extremely well together.
- Bluepill. A simple long-running process management tool similar to god, and the icing on our quandary cake. We use it to control and monitor our Rails apps.
Each of our apps has a separate config file which is read when the Bluepill load command is issued (eg. bluepill load redmine.pill). The pill file contains variables that are specific to each app (name, path, mode, RVM ruby version). redmine.pill -
APP_NAME = "redmine" RAILS_ROOT = "/var/www/redmine" RAILS_ENV = "production" RUBY = "ree-1.8.7-2010.02"
The main Bluepill config file has a generic start command which looks like this -
And finally, the launch.sh script which ties it all together when we issue a Bluepill start command (eg. bluepill redmine start) -
#!/bin/bash
# $1 - rvm ruby version, $2 - rails_root, $3 - rails_env
. /usr/local/rvm/scripts/rvm # source RVM
rvm use $1 # switch to the proper ruby
if [[ $1 =~ "1.8" ]]; then
UNICORN=unicorn_rails
else
UNICORN=unicorn
fi
$UNICORN -e "ENV['RAILS_ROOT']='$2'" -c /etc/rails/unicorn.rb -E $3 -D





