Capistrano: Deploy Rails Twice To The Same Machine
Join the DZone community and get the full member experience.Join For Free
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
Opinions expressed by DZone contributors are their own.