Capistrano and Passenger

To use Capistrano on a Passenger enabled host, you need to add the following lines to your config/deploy.rb file.

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"
  end

  desc "Stop task is a deploy.web.disable with mod_rails"
  task :stop, :roles => :app do
    deploy.web.disable
  end

  desc "Start task is a deploy.web.enable with mod_rails"
  task :start, :roles => :app do
    deploy.web.enable
  end
end

Because in passenger there is no way of stopping or starting your Rails application, I’ve changed the deploy:start and deploy:stop to deploy:web:enable and deploy:web:disable. The deploy:restart is used by the deploy task, so now your deployment works as expected.

Update:
Don’t forget to add the rewrite rules to your apache virtual host config, otherwise the enable disable tasks won’t work.

RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /system/maintenance.html [L]
This entry was posted in Ruby on Rails and tagged , , , . Bookmark the permalink.

3 Responses to Capistrano and Passenger

  1. Karl Varga says:

    My rewrite conditions are slightly different and dare I say better? The nice thing about this approach is you get the proper HTTP status code being returned with the maintenance page so that robots know it’s just a temporary problem. Also, it allows robots to ready the robots files and any sitemaps you may have. I’ve also included images so that you can put images like logos and stuff in your maintenance page and have them display properly.

    ErrorDocument 503 /system/maintenance.html
    RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
    RewriteCond %{SCRIPT_FILENAME} !maintenance.html
    RewriteCond %{REQUEST_URI} !^/images/
    RewriteCond %{REQUEST_URI} !^/robots.txt
    RewriteCond %{REQUEST_URI} !^/sitemap
    RewriteRule ^.*$ – [redirect=503,last]

  2. Tom says:

    I do agree with the fact that your rewrite rules are an improvement over mine. I personally will not include the sitemap to the exceptions because my app will generate them automatically. Although I like the fact that your rules return the proper HTTP status codes.

  3. Pingback: Tnux.net ยป Capistrano and Passenger part 2

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>