The following recipe enables you to deploy on a Passenger (mod_Rails) server with Capistrano. It’s a ready to use boilerplate, you just need to store it somewhere in your rails project (for example in the config/deploy folder) and require it from your deploy.rb file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | # # = Capistrano Passenger deploy tasks # # Provides tasks for deploying a Rails application with Passenger (aka mod_rails). # # Category:: Capistrano # Package:: Passenger # Author:: Simone Carletti # Copyright:: 2007-2008 The Authors # License:: MIT License # Link:: http://www.simonecarletti.com/ # Source:: http://gist.github.com/2769 # # unless Capistrano::Configuration.respond_to?(:instance) abort "This extension requires Capistrano 2" end Capistrano::Configuration.instance.load do namespace :passenger do desc <<-DESC Restarts your application. \ This works by creating an empty `restart.txt` file in the `tmp` folder as requested by Passenger server. DESC task :restart, :roles => :app, :except => { :no_release => true } do run "touch #{current_path}/tmp/restart.txt" end desc <<-DESC Starts the application servers. \ Please note that this task is not supported by Passenger server. DESC task :start, :roles => :app do logger.info ":start task not supported by Passenger server" end desc <<-DESC Stops the application servers. \ Please note that this task is not supported by Passenger server. DESC task :stop, :roles => :app do logger.info ":stop task not supported by Passenger server" end end namespace :deploy do desc <<-DESC Restarts your application. \ Overwrites default :restart task for Passenger server. DESC task :restart, :roles => :app, :except => { :no_release => true } do passenger.restart end desc <<-DESC Starts the application servers. \ Overwrites default :start task for Passenger server. DESC task :start, :roles => :app do passenger.start end desc <<-DESC Stops the application servers. \ Overwrites default :start task for Passenger server. DESC task :stop, :roles => :app do passenger.stop end end end |
This extension creates the following Capistrano tasks under the passenger namespace:
- start
- stop
- restart
Additionally, it overwrites the default Capistrano deploy:start/stop/restart tasks to fully integrate Passenger into your current deployment strategy.
Please note that, due to Passenger architecture, only restart task is supported. start and stop task are available only for compatibility purpose. Invoking deploy:start or deploy:stop will simply return a warning.
The most recent version of this recipe is available as a Gist (#3102).
Does the cap deploy work with mod_rails? Touching the restart.txt file in a NEW directory (as this script does) would seem to me to confuse the mod_rails module – is it smart enough to drop the old rails environment and use the new one under the new release directory?
Yes, it does.
This script touches the restart.txt file in the /current directory. By Capistrano convenction, current is a symlink to the most recently deployed application instance and this is the folder configured in your Apache virtual host.
mod_rails requires the restart.txt file to be stored at tmp/restart.txt path from the document directory and this is exactly what this script does.