Skip to content

Instantly share code, notes, and snippets.

@jnewland
Created August 22, 2010 20:39
Show Gist options
  • Save jnewland/544259 to your computer and use it in GitHub Desktop.
Save jnewland/544259 to your computer and use it in GitHub Desktop.
execute capistrano commands serially
server 'localhost', :test
server '127.0.0.1', :test2
task :test_serially do
serially do
run 'date && sleep 5'
end
end
def serially(&block)
original = ENV['HOSTS']
find_servers_for_task(self.current_task).each do |server|
ENV['HOSTS'] = server.host
yield
end
ensure
ENV['HOSTS'] = original
end
$ cap test_serially
* executing `test_serially'
* executing "date && sleep 5"
servers: ["localhost"]
[localhost] executing command
** [out :: localhost] Sun Aug 22 16:38:45 EDT 2010
command finished
* executing "date && sleep 5"
servers: ["127.0.0.1"]
[127.0.0.1] executing command
** [out :: 127.0.0.1] Sun Aug 22 16:38:51 EDT 2010
command finished
@danielfm
Copy link

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment