Created
March 29, 2010 10:10
-
-
Save gakshay/347693 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# deploy.rb | |
# sample capistrano deploy file | |
# USAGE: | |
# => cap build deploy:setup | |
# => cap build deploy | |
# => cap staging restart | |
# => Do notice after deploy callbacks | |
task :staging do | |
role :web, "<server-1>" | |
role :app, "<server-1>" | |
role :db, "<server-1>", :primary => true | |
set :application, "<staging-app-name>" | |
end | |
task :build do | |
role :web, "<server-2>" | |
role :app, "<server-2>" | |
role :db, "<server-2>", :primary => true | |
set :application, "<build-app-name>" | |
end | |
set(:deploy_to) { "/var/www/apps/#{application}" } | |
set :keep_releases, 5 | |
set :user, "<ssh-user>" | |
set :password, "<ssh-user-password>" | |
set :group, "<user-group>" | |
set :use_sudo, false | |
set :repository, "git@github.com:gakshay/<app_name>.git" | |
set :scm, "git" | |
set :branch, "<branch-needs-to-be-deployed>" | |
set :scm_username, "<scm-username>" | |
set :scm_password, "<scm-passsword>" | |
after "deploy", "deploy:cleanup" | |
after "deploy:migrations", "deploy:cleanup" | |
after "deploy:update_code", "deploy:symlink_configs", "deploy:symlink_custom" | |
namespace :files do | |
desc "list all the files" | |
task :list, :roles => :app do | |
run "cd #{deploy_to}; ls -l" | |
end | |
desc "tree structure of the files" | |
task :tree, :roles => :app do | |
run "cd #{deploy_to}; tree" | |
end | |
end | |
namespace :deploy do | |
desc "Disable your web application" | |
namespace :web do | |
task :disable, :roles => :web do | |
on_rollback { delete "#{shared_path}/system/maintenance.html" } | |
maintenance = File.read("./public/maintenance.html") | |
put maintenance, "#{shared_path}/system/maintenance.html", | |
:mode => 0644 | |
end | |
end | |
desc "Restart Application" | |
task :restart, :roles => :app do | |
run "touch #{deploy_to}/#{shared_dir}/tmp/restart.txt" | |
end | |
desc "Setup Standard Configuration Links" | |
task :symlink_configs, :roles => [:app] do | |
# relink shared database configuration | |
run "ln -nfs #{deploy_to}/#{shared_dir}/config/database.yml #{release_path}/config/database.yml" | |
# relink shared tmp dir | |
run "rm -rf #{release_path}/tmp" # technically shouldn't be in svn/git | |
run "ln -nfs #{deploy_to}/#{shared_dir}/tmp #{release_path}/tmp" | |
end | |
desc "Custom Symlinks" | |
task :symlink_custom, :roles => [:app] do | |
run "if [ -d #{release_path}/public/gallery_photos ]; then mv #{release_path}/public/gallery_photos #{release_path}/public/gallery_photos.bak; fi; ln -nfs #{shared_path}/directories/gallery_photos #{release_path}/public/gallery_photos" | |
run "if [ -d #{release_path}/public/profile_photos ]; then mv #{release_path}/public/profile_photos #{release_path}/public/profile_photos.bak; fi; ln -nfs #{shared_path}/directories/profile_photos #{release_path}/public/profile_photos" | |
end | |
end | |
desc "Restart Apache." | |
task :restart_apache, :roles => :app do | |
run "apache2ctl restart" | |
end | |
desc 'Dumps the production database to db/production_data.sql on the remote server' | |
task :remote_db_dump, :roles => :db, :only => { :primary => true } do | |
run "cd #{deploy_to}/#{current_dir} && " + | |
"#{rake} RAILS_ENV=#{rails_env} db:database_dump --trace" | |
end | |
desc 'Cleans up data dump file' | |
task :remote_db_cleanup, :roles => :db, :only => { :primary => true } do | |
delete "#{deploy_to}/#{current_dir}/db/production_data.sql" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment