Archive | August 2007

Capistrano 2, Multistage, and Mongrel Clusters

Recently I have been configuring Mongrel and Capistrano for a few apps that I have been working on. I use FastCGI on shared hosts, but if I have a bit more control on a VPS or a dedicated server I prefer to use Mongrel since it is easier to install and configure and it is also more stable. Here is what I do to get a Mongrel cluster up and running using Capistrano and the extension that Jamis Buck also wrote named Multistage.

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/" -p 8000 -N 4 -C config/mongrel_development.yaml
~/rails_app $ mongrel_rails cluster::configure -e staging -c "/home/www/apps/" -p 8010 -N 4 -C config/mongrel_staging.yaml
~/rails_app $ mongrel_rails cluster::configure -e production -c "/home/www/apps/" -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"

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.


Active Merchent Support for the Verifi Payment Gateway

A few months ago I was working on a project that required me to setup credit card processing. My client already had a merchant account using the Verifi gateway and instead of talking my client into using a different gateway or doing something from scratch, i figured i would just add support for Verifi for the Active Merchant Rails plug-in and then give back the code to the plug-in project. So if you are using the Verifi payment gateway you have a great rails plug-in with support for it.