Platinum Partner

Capistrano: Deploy Rails Twice To The Same Machine

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"
  end
end
{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}