Capistrano 2, Multistage, and Mongrel Clusters
Make sure you have ruby, rails, capistrano, capistrano-ext, mongrel, palmtree and mongrel_cluster gems installed on your system.
To generate your cluster files you can run the following commands with your specific details of course. ;)
~ $ cd rails_app ~/rails_app $ mongrel_rails cluster::configure -e development -c "/home/www/apps/web2.0app.com" -p 8000 -N 4 -C config/mongrel_development.yaml ~/rails_app $ mongrel_rails cluster::configure -e staging -c "/home/www/apps/web2.0app.com" -p 8010 -N 4 -C config/mongrel_staging.yaml ~/rails_app $ mongrel_rails cluster::configure -e production -c "/home/www/apps/web2.0app.com" -p 8020 -N 4 -C config/mongrel_production.yaml
Now all you need to do is configure Capistrano config/deploy.rb file to make use of these cluster files and the Multistage extension for Capistrano. If you don't how to setup Multistage, you can do a search for it or read my other post in it.
require 'palmtree/recipes/mongrel_cluster'
set :stages, %w(staging production development)
set :default_stage, "development"
require 'capistrano/ext/multistage'
...
set(:mongrel_conf) { "#{current_path}/config/mongrel_cluster.yml" }
...
deploy.task :after_update_code, :roles => [:web] do
desc "Copying the right mongrel cluster config for the current stage environment."
run "cp -f #{release_path}/config/mongrel_#{stage}.yml #{release_path}/config/mongrel_cluster.yml"
end
In order for the correct mongrel cluster to start you will need to have a recipe in your deploy that ensures that the correct cluster file is renamed to the config/mongrel_cluster.yml and then it is used by Capistranos' mongrel:cluster:restart task.
Admittedly there are many more things that need to be done before and after this little tip, but I thought that this may help someone who may need to bridge their understanding of how easy it is to solve the Mongrel cluster on different stages problem.
