Created
September 14, 2012 20:42
-
-
Save unorthodoxgeek/3724674 to your computer and use it in GitHub Desktop.
Capistrano deploy.rb
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
namespace :deploy do | |
task :start, :roles => :web, :except => { :no_release => true } do | |
run "cd #{current_path} && rvmsudo #{unicorn_binary} -c #{unicorn_config} -E #{env} -D" | |
end | |
task :stop, :roles => :web, :except => { :no_release => true } do | |
run "ps aux | grep unicorn | grep master | grep -v grep | awk {'print $2'} | xargs -r sudo kill -s QUIT" | |
#run "rvmsudo kill -s QUIT `cat #{unicorn_pid}`" | |
end | |
#notice that we're doing sort of a rolling restart, that's not it (there's no sleep) but because we check if there's a running unicorn server before we send the USR2 we need to run the tasks for each server separately | |
# unicorn_binary is the command used to run unicorn (bundle exec unicorn) and the unicorn_config is the path to the config file | |
task :restart, :roles => :web, :except => { :no_release => true } do | |
servers = find_servers_for_task(current_task) | |
servers.each do |server| | |
grep = capture "ps aux | grep unicorn | grep master | grep -v grep; true", :hosts => server | |
#if unicorn isn't running, start it | |
if grep.to_s == "" | |
run "cd #{current_path} && rvmsudo #{unicorn_binary} -c #{unicorn_config} -E #{env} -D", :hosts => server | |
else | |
#otherwise, restart | |
run "sudo kill -s USR2 `cat #{unicorn_pid}`", :hosts => server | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment