Jun
23
2008
Capistrano and Passenger
Posted by: Tom in Ruby on Rails, tags: Apache, Capistrano, Passenger, Ruby on RailsTo 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]
Entries (RSS)
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]
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.
[...] Karl Varga pointed out in his comment on my previous post on Capistrano and Passenger (here) my apache rewrite rules did not send back the proper HTTP status codes. Now with the improved and [...]