Wednesday, 20 February 2008

Using Monit to manage your app servers in Capistrano 2

If you've gone to the trouble of setting up monit on your server (or you're using a Brightbox like I am), why not let it take the strain of starting and stopping your app servers during a Capistrano deployment.

Just stick this code snippet at the bottom of the deploy.rb file.

# Redefine the application server controls to use monit.

namespace :deploy do
%W(start stop restart).each do |event|
desc "#{event} using Monit"
task event, :except => { :no_release => true } do
sudo "/usr/sbin/monit -g #{application} #{event} all"