DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Capistrano: Deploy Rails Twice To The Same Machine

  • submit to reddit
        Capistrano is oriented so it deploys to the same directory on several machines. This means you can't deploy to two different locations on the same machine.  The following recipe in Capfile will allow you to duplicate your main rails app in a second directory. You can schedule it to run automatically with every deploy or just do it manually. I included database migrations by default. Remove the shared config line if you don't have it. Edit the directories to match yours.
namespace :yournamespace do
  desc "Synchronize main_app to second_app"
  task :sync_apps, :roles => [:app, :db, :web] do
    puts "synchronizing main_app to second_app"
    run "rsync -a /var/rails/main_app/ /var/rails/second_app --exclude=/shared --delete"
    run "for file in `find /var/rails/second_app -type l`; do TARGET=`readlink $file | sed -e \"s/main_app/second_app/\"`; rm $file; ln -s $TARGET $file; done;"
    run "cp /var/rails/second_app/shared/config/* /var/rails/second_app/current/config";
    run "cd /var/rails/second_app/current; /usr/local/bin/rake RAILS_ENV=production db:migrate;"
    run "touch tmp/restart.txt"


Noel Peden replied on Mon, 2012/05/07 - 6:05pm

This is now done better with the Multitage extension. 

 Simply create two stages and place different :deploy_to settings in each. 

Cici Wirachmat replied on Sun, 2011/10/16 - 11:39am DZone we are helped how to devel Website>