Skip to content

Instantly share code, notes, and snippets.

@jwo
Created January 2, 2012 19:58
Show Gist options
  • Save jwo/1551881 to your computer and use it in GitHub Desktop.
Save jwo/1551881 to your computer and use it in GitHub Desktop.
Capistrano with Unicorn Reloading
set :application, "yyyyyyyyyyy"
set :repository, "here-be-your-githubs"
set :scm, :git
set :branch, "master"
set :user, "xxxxxxxx"
set :scm_verbose, true
default_run_options[:pty] = true
set :deploy_via, :remote_cache
ssh_options[:forward_agent] = true
role :web, "XXXXXX"
role :app, "XXXXXX"
role :db, "XXXXXX", :primary => true
require 'bundler/capistrano'
require "whenever/capistrano"
set :whenever_command, "bundle exec whenever"
after "deploy:update_code", "assets:precompile"
after "deploy:restart", "deploy:cleanup"
set :rails_env, "production"
puts "*********** DEPLOYING TO PRODUCTION *********"
puts "ARE YOU SURE YOU WANT TO DO THIS? (y or n)"
input = STDIN.gets.strip.downcase
if input != 'y'
abort("ABORTING DEPLOYMENT")
end
set :unicorn_pid, "#{current_path}/tmp/pids/unicorn.pid"
namespace :unicorn do
desc "start unicorn"
task :start, :roles => :app, :except => { :no_release => true } do
run "cd #{current_path} && #{try_sudo} bundle exec unicorn_rails -c #{current_path}/config/unicorn/#{rails_env}.rb -E #{rails_env} -D"
end
desc "stop unicorn"
task :stop, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} kill `cat #{unicorn_pid}`"
end
desc "graceful stop unicorn"
task :graceful_stop, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} kill -s QUIT `cat #{unicorn_pid}`"
end
desc "reload unicorn"
task :reload, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} kill -s USR2 `cat #{unicorn_pid}`"
end
after "deploy:restart", "unicorn:reload"
end
namespace :rake do
desc "Run a task on a remote server."
# run like: cap staging rake:invoke task=a_certain_task
task :invoke do
run("cd #{deploy_to}/current && bundle exec rake #{ENV['task']} RAILS_ENV=#{rails_env}")
end
end
namespace :assets do
desc "Precompile assets"
task :precompile do
run("cd #{release_path}; RAILS_ENV=#{rails_env} RAILS_GROUPS=assets bundle exec rake assets:precompile")
end
end
namespace :indexes do
desc "Create Mongoid Indexes"
task :create, :roles=>:app do
run "cd #{current_path}; RAILS_ENV=#{rails_env} bundle exec rake db:mongoid:create_indexes"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment