Can Capistrano Execute Tasks on Hosts Consecutively?

devinfoley picture devinfoley · Nov 5, 2010 · Viewed 8.3k times · Source

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?

Answer

silvamerica picture silvamerica · Jan 1, 2011

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