Created
April 24, 2013 14:13
-
-
Save dbkbali/5452429 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
require "bundler/capistrano" | |
set :port, XXXX | |
server "XX.XXX.XXX.XX", :web, :app, :db, primary: true | |
set :application, "XXXXXXX" | |
set :user, "XXXXXXX" | |
set :deploy_to, "/home/#{user}/apps/#{application}" | |
set :deploy_via, :remote_cache | |
set :use_sudo, false | |
set :scm, "git" | |
set :repository, "git@github.com:XXXXXX/#{application}.git" | |
set :branch, "rails_4" | |
set :default_environment, { | |
'RBENV_ROOT' => '/home/deployer/.rbenv', | |
'PATH' => "/home/deployer/.rbenv/shims:/home/deployer/.rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH" | |
} | |
default_run_options[:pty] = true | |
ssh_options[:forward_agent] = true | |
after "deploy", "deploy:cleanup" # keep only the last 5 releases | |
namespace :dragonfly do | |
desc "Symlink the Rack::Cache files" | |
task :symlink, roles: [:app] do | |
run "mkdir -p #{shared_path}/tmp/dragonfly && ln -nfs #{shared_path}/tmp/dragonfly #{release_path}/tmp/dragonfly" | |
end | |
end | |
after 'deploy:update_code', 'dragonfly:symlink' | |
namespace :unicorn do | |
%w[start stop restart].each do |command| | |
desc "#{command} unicorn server" | |
task command, roles: :app, except: {no_release: true} do | |
run "service unicorn_#{application} #{command}" | |
end | |
end | |
end | |
after 'deploy:cold', 'unicorn:restart' | |
namespace :memcached do | |
desc "Restart Memcached" | |
task :restart, roles: :app do | |
sudo "nohup /etc/init.d/memcached restart &" | |
end | |
end | |
after 'deploy:cold', 'memcached:restart' | |
namespace :logs do | |
task :rails do | |
stream "tail -f #{current_path}/log/#{rails_env}.log" | |
end | |
task :unicorn do | |
stream "tail -f #{current_path}/log/unicorn.log" | |
end | |
end | |
namespace :cache do | |
task :clear, roles: :app do | |
run "cd #{current_path} && bin/rake cache:clear env=#{rails_env}" | |
end | |
end | |
namespace :deploy do | |
namespace :assets do | |
task :precompile, roles: assets_role, except: { no_release: true } do | |
run <<-CMD.compact | |
cd -- #{latest_release.shellescape} && | |
#{rake} RAILS_ENV=#{rails_env.to_s.shellescape} #{asset_env} assets:precompile | |
CMD | |
end | |
end | |
task :setup_config, roles: :app do | |
sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}" | |
sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}" | |
run "mkdir -p #{shared_path}/config" | |
run "mkdir -p #{shared_path}/tmp" | |
run "chmod g+w #{shared_path}/tmp" | |
put File.read("config/mongoid.example.yml"), "#{shared_path}/config/mongoid.yml" | |
put File.read("config/application.example.yml"), "#{shared_path}/config/application.yml" | |
puts "Now edit the config files in #{shared_path}." | |
end | |
after "deploy:setup", "deploy:setup_config" | |
task :symlink_config, roles: :app do | |
run "ln -nfs #{shared_path}/config/mongoid.yml #{release_path}/config/mongoid.yml" | |
run "ln -nfs #{shared_path}/config/application.yml #{release_path}/config/application.yml" | |
end | |
after "deploy:finalize_update", "deploy:symlink_config" | |
desc "Make sure local git is in sync with remote." | |
task :check_revision, roles: :web do | |
unless `git rev-parse HEAD` == `git rev-parse origin/master` | |
puts "WARNING: HEAD is not the same as origin/master" | |
puts "Run `git push` to sync changes." | |
exit | |
end | |
end | |
before "deploy", "deploy:check_revision" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment