Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Capistrano Execute Tasks on Hosts Consecutively?

Tags:

capistrano

I am using Capistrano to manage a Java web app that is running on several load balanced servers. Certain tasks (such as config changes) require a server restart, or app redeploy, during which the server becomes non-responsive.

If Capistrano could perform these tasks on servers consecutively, vs. concurrently, only one machine in the farm would go down at a time, and the load balancer would ensure that no requests are lost. However, from what I can tell, Capistrano only performs operations on servers concurrently.

To be clear, I'm not trying to execute different tasks consecutively. I'm trying to execute the same task on different servers consecutively.

I can think of some ways of hacking this in my configuration, but it seems like there should be a flag I can set somewhere.

Anybody know how to do this?

like image 245
devinfoley Avatar asked Nov 05 '10 22:11

devinfoley


2 Answers

I use this to restart my servers in series, instead of in parallel:

task :my_task, :roles => :web do
  find_servers_for_task(current_task).each do |server|
    run "[task command here]", :hosts => server.host
  end
end
like image 51
silvamerica Avatar answered Oct 09 '22 01:10

silvamerica


You can set :max_hosts for the task to limit its parallelism:

:max_hosts - specifies the maximum number of hosts that should be selected at a time. If this value is less than the number of hosts that are selected to run, then the hosts will be run in groups of max_hosts. The default is nil, which indicates that there is no maximum host limit. Please note this does not limit the number of SSH channels that can be open, only the number of hosts upon which this will be called.

Example:

desc "Say hello, one at a time"
task :hello, :roles => :app, :max_hosts => 1 do
  run "echo serial hello ; sleep 0 ; echo serial hello DONE"
  # Note that task parameters do NOT get automatically passed on to
  # other tasks, i.e. a call to "deploy:restart" would be
  # unaffected by :max_hosts set here. Example:
  self.send(:normal_hello)
end

desc "Say hello, everybody"
task :normal_hello, :roles => :app do
  run "echo 'normal (parallel) hello' ; sleep 10 ; echo normal hello DONE"
end
like image 39
conny Avatar answered Oct 09 '22 01:10

conny