Skip to content

Instantly share code, notes, and snippets.

@babysnakes
Created January 4, 2012 05:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save babysnakes/1558678 to your computer and use it in GitHub Desktop.
Save babysnakes/1558678 to your computer and use it in GitHub Desktop.
Trying to create rolling deploy via capistrano.
role :servers, "server1", "server2"
set :user, 'ubuntu'
def stop_load_balancer
run "echo service registerelb stop"
end
def start_load_balancer
run "echo service registerelb start"
end
def stop_app
run "echo service app stop"
end
def start_app
run "echo service app start"
end
namespace :deploy do
desc "Deploy"
task :default, :roles => :servers, :max_hosts => 1 do
stop_load_balancer
stop_app
start_app
start_load_balancer
end
end
__END__
Here is the output of running the command. As you can see it runs each
remote command on both servers (consecutively) before getting to the next
remote command. This WILL cause downtime!
╭─haim@sunra ~/cap_tests ‹1.8.7-p352›
╰─$ cap -f deploy_via_methods.rb deploy 1 ↵
* executing `deploy'
* executing "echo service registerelb stop"
servers: ["server1", "server2"]
[server1] executing command
** [out :: server1] service registerelb stop
command finished in 1404ms
[server2] executing command
** [out :: server2] service registerelb stop
command finished in 1124ms
* executing "echo service app stop"
servers: ["server1", "server2"]
[server1] executing command
** [out :: server1] service app stop
command finished in 1515ms
[server2] executing command
** [out :: server2] service app stop
command finished in 1239ms
* executing "echo service app start"
servers: ["server1", "server2"]
[server1] executing command
** [out :: server1] service app start
command finished in 969ms
[server2] executing command
** [out :: server2] service app start
command finished in 823ms
* executing "echo service registerelb start"
servers: ["server1", "server2"]
[server1] executing command
** [out :: server1] service registerelb start
command finished in 1759ms
[server2] executing command
** [out :: server2] service registerelb start
command finished in 664ms
role :servers, 'server1', 'server2'
set :user, 'ubuntu'
namespace :deploy do
desc "Deploy"
task :default do
find_servers(:roles => :servers).each do |server|
run "echo service registerelb stop", :hosts => server
run "echo service app stop", :hosts => server
run "echo service app start", :hosts => server
run "echo service registerelb start", :hosts => server
end
end
end
__END__
This setup actually works as I want it to work (rolling deploy without
downtime) but it will cause code duplication because I want to be able
to run each command separately.
╭─haim@sunra ~/cap_tests ‹1.8.7-p352›
╰─$ cap -f rolling.rb deploy
* executing `deploy'
* executing "echo service registerelb stop"
servers: ["server1"]
[server1] executing command
** [out :: server1] service registerelb stop
command finished in 1095ms
* executing "echo service app stop"
servers: ["server1"]
[server1] executing command
** [out :: server1] service app stop
command finished in 337ms
* executing "echo service app start"
servers: ["server1"]
[server1] executing command
** [out :: server1] service app start
command finished in 338ms
* executing "echo service registerelb start"
servers: ["server1"]
[server1] executing command
** [out :: server1] service registerelb start
command finished in 352ms
* executing "echo service registerelb stop"
servers: ["server2"]
[server2] executing command
** [out :: server2] service registerelb stop
command finished in 1127ms
* executing "echo service app stop"
servers: ["server2"]
[server2] executing command
** [out :: server2] service app stop
command finished in 347ms
* executing "echo service app start"
servers: ["server2"]
[server2] executing command
** [out :: server2] service app start
command finished in 325ms
* executing "echo service registerelb start"
servers: ["server2"]
[server2] executing command
** [out :: server2] service registerelb start
command finished in 330ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment