Created
June 12, 2013 10:20
-
-
Save tarapon/5764231 to your computer and use it in GitHub Desktop.
Capistrano deploy script example example
This file contains hidden or 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 "capistrano" | |
require "bundler/capistrano" | |
require "capistrano-resque" | |
set :default_environment, { | |
#path to your ruby environment on server | |
'PATH' => "/usr/local/rvm/rubies/ruby-1.9.3-p392/bin/:/usr/local/rvm/bin:$PATH" | |
} | |
ssh_options[:forward_agent] = true | |
default_run_options[:pty] = true | |
set :application, "MyApplication" | |
set :rails_env, "production" | |
set :domain, "[email protected]" | |
set :deploy_to, "/usr/share/nginx/www/#{application}" | |
set :unicorn_conf, "#{deploy_to}/current/config/unicorn.rb" | |
set :unicorn_pid, "#{deploy_to}/shared/unicorn.pid" | |
set :shared_children, shared_children + %w{public/uploads} | |
set :use_sudo, fetch(:sudo, false) | |
set :scm, :mercurial #or :git | |
set :repository, "ssh://[email protected]/user/repository" | |
set :branch, fetch(:branch, "default") | |
role :web, domain # Your HTTP server, Apache/etc | |
role :app, domain # This may be the same as your `Web` server | |
role :db, domain, :primary => true # This is where Rails migrations will run | |
#resque | |
role :resque_worker, domain | |
role :resque_scheduler, domain | |
set :workers, {'*' => 1} | |
before "deploy:update_code", "assets:precompile" | |
after "deploy:create_symlink", "deploy:migrate", "assets:upload" | |
after "deploy:restart", "resque:stop", "resque:start" | |
after "deploy:restart", "mailman:restart" | |
namespace :deploy do | |
task :restart do | |
run "if [ -f #{unicorn_pid} ] && [ -e /proc/$(cat #{unicorn_pid}) ]; then kill -USR2 `cat #{unicorn_pid}`; else cd #{deploy_to}/current && bundle exec unicorn -c #{unicorn_conf} -E #{rails_env} -D; fi" | |
end | |
task :start do | |
run "cd #{deploy_to}/current && bundle exec unicorn -c #{unicorn_conf} -E #{rails_env} -D" | |
end | |
task :stop do | |
run "if [ -f #{unicorn_pid} ] && [ -e /proc/$(cat #{unicorn_pid}) ]; then kill -QUIT `cat #{unicorn_pid}`; fi" | |
end | |
task :migrate do | |
run "cd #{deploy_to}/current && bundle exec rake db:migrate RAILS_ENV=#{rails_env}" | |
end | |
end | |
#mailman if you have | |
namespace :mailman do | |
[:start, :stop, :status, :restart].each do |task_name| | |
task task_name do | |
run "cd #{deploy_to}/current && bundle exec rake mailman:#{task_name.to_s} RAILS_ENV=#{rails_env}" | |
end | |
end | |
end | |
#compile assets localy | |
namespace :assets do | |
task :precompile do | |
run_locally("bundle exec rake assets:clean") | |
run_locally("bundle exec rake assets:precompile") | |
run_locally("touch assets.tgz && rm assets.tgz") | |
run_locally("tar zcf assets.tgz public/assets/") | |
run_locally("mv assets.tgz public/assets/") | |
end | |
task :upload do | |
transfer(:up, "public/assets/assets.tgz", "#{deploy_to}/current/assets.tgz") | |
run "cd #{deploy_to}/current/; tar zxf assets.tgz; rm assets.tgz" | |
run_locally("bundle exec rake assets:clean") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment