Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

capistrano sequential restarts

I have capistrano configured to deploy across three physical servers. I would like to configure the restart task to sequentially go to each server and restart the app rather than the default way of going to all servers at once.

Here is the current deploy task:

namespace :deploy do

  task :start, :roles => :app, :except => { :no_release => true } do 
    run "cd #{current_path} && bundle exec unicorn_rails -c #{current_path}/config/unicorn.rb -E #{rails_env} -D"
  end

  task :stop, :roles => :app, :except => { :no_release => true } do 
    run "kill `cat #{current_path}/tmp/pids/unicorn.pid`"
  end

  task :restart, :roles => :app, :except => { :no_release => true } do
    stop
    sleep(10)
    start
  end

end

I am thinking something like this:

#this does not work 
task :sequential_restart do
   find_servers(:roles => :app).each
    restart
   end
 end

Any Ideas?

like image 296
Aaron Renoir Avatar asked Jan 10 '12 20:01

Aaron Renoir


1 Answers

I do something very similar using the HOSTFILTER environment variable, which effectively scopes everything to the hosts matching the filter.

Something like

find_servers(:roles => :app).each do |server|
  ENV['HOSTFILTER'] = server.host
  restart
end
ENV['HOSTFILTER'] = nil

should do the trick.

like image 157
Frederick Cheung Avatar answered Sep 24 '22 14:09

Frederick Cheung