Skip to content

Instantly share code, notes, and snippets.

@erpe
Created April 18, 2013 11:11
Show Gist options
  • Save erpe/5411954 to your computer and use it in GitHub Desktop.
Save erpe/5411954 to your computer and use it in GitHub Desktop.
capistrano task to deal with unicorn restarts during deployment
namespace :unicorn do
desc "Zero-downtime restart of Unicorn"
task :restart, :except => { :no_release => true } do
# you can use this signal if preload_app == false
# run "kill -s HUP `cat #{shared_path}/pids/unicorn.pid`"
# use this signal if preload_app == true
run "kill -s USR2 `cat #{shared_path}/pids/unicorn.pid`"
# give unicorn some seconds to create unicorn.pid.oldbin
sleep 3
# see processes:
run "ps aux | grep 'unicorn master'"
run "kill -s QUIT `cat #{shared_path}/pids/unicorn.pid.oldbin`"
end
desc "Start unicorn"
task :start, :except => { :no_release => true } do
run "cd #{current_path}; RAILS_ENV=#{rails_env} bundle exec unicorn -c config/unicorn.rb -D -E #{rails_env}"
end
desc "Stop unicorn"
task :stop, :except => { :no_release => true } do
run "kill -s QUIT `cat #{shared_path}/pids/unicorn.pid`"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment