Hi! I'm Nathan Hoad

Deploy a Rails app on Passenger with Capistrano

To get Capistrano to play nice with Passenger you need to override some of Capistrano's default deploy behaviour. After a Rails app gets deployed Capistrano will attempt to restart it but does so in a way that isn't relevant to Passenger. To restart a Rails app on Passenger all you need is to touch tmp/restart.txt. In order to get Capistrano to do this we need to override the restart task.

In your config/deploy.rb file add this code:

namespace :deploy do
  desc "Restarting mod_rails with restart.txt"
  task :restart, :roles => :app, :except => { :no_release => true } do
    run "touch #{current_path}/tmp/restart.txt"

If you don't have a config/deploy.rb file then you should probably read Getting started with Capistrano for Rails first.

The start and stop tasks are also irrelevant for Passenger so we can override them to do nothing:

[:start, :stop].each do |t|
  desc "#{t} task isn't needed for Passenger"
  task t, :roles => :app do
    # nothing

Then you can just deploy like you normally would with Capistrano:

cap deploy

And that should be it .

If I just made your day a little better then thank me with a coffee or maybe a a pizza