I use this script, and it works for me (although, I'm sure I could
improve it..) - hope this helps!
================ START deploy.rb =============
set :application, "MY_APP"
set :user, "your_username"
set :admin_runner, user
set :rails_env, 'test'
set :deploy_to, "/path/to/MY_APP/#{application}" # this is the path on
your server you're deploying to
set :deploy_via, :copy
set :scm, :git
set :repository, "/My/local/git/repository"
set :branch, "master"
set :port, YOUR_PORT_HERE
set :location, "
your_domain.com"
role :app, location
role :web, location
role :db, location, :primary => true
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
[:start, :stop].each do |t|
desc "#{t} task is a no-op with mod_rails"
task t, :roles => :app do ; end
end
# RailsEnv is set in apache my_app vhost config, but also set it in
environment.rb,
# so applicaitons can acccess the RAILS_ENV constant.
task :set_rails_env do
tmp = "#{current_release}/MY_APP/tmp/environment.rb"
final = "#{current_release}/MY_APP/config/environment.rb"
run <<-BASH
echo "ENV['RAILS_ENV'] ||= '#{rails_env}'" > #{tmp};
cat #{final} >> #{tmp} && mv #{tmp} #{final};
BASH
end
end
# After the current release has been updated, re-create the symbolic
links on the server
# so that the database.yml and uploads (in shared directory) are
"understood" by the current release
namespace(:customs) do
task :config, :roles => :app do
run <<-CMD
ln -nfs #{shared_path}/system/database.yml #{release_path}/
MY_APP/config/database.yml
CMD
end
task :symlink, :roles => :app do
run <<-CMD
ln -nfs #{shared_path}/system/uploads #{release_path}/MY_APP/
public/uploads
CMD
end
end
after "deploy:update_code", "customs:config"
after "deploy:symlink","customs:symlink"
after "deploy", "deploy:cleanup"
after "deploy:finalize_update", "deploy:set_rails_env"