On Aug 26, 2008, at 5:37 PM, ben.koski wrote:
> Is there some way of staggering server restarts post-deploy when there
> are multiple servers in a role? My servers sometimes take a few
> seconds to stabilize post-deploy, and I'd like to avoid bouncing all
> of them at once.
this is what i use - it's quite simple, but works very well.
task 'deploy-preview' do
deploy_serially_to :boxes => [server_a], :stage => :preview
end
task 'deploy-training' do
deploy_serially_to :boxes => [server_b, server_c], :stage
=> :training
end
task 'deploy-production' do
deploy_serially_to :boxes => [server_d, server_e,
server_f], :stage => :production
end
def deploy_serially_to options = {}
require 'timeout'
require 'highline'
boxes = [ options['boxes'] || options[:boxes] ].flatten.compact
last = boxes.pop
abort 'no boxes!' unless last
stage = ( options['stage'] || options[:stage] ).to_s
abort 'no stage!' if stage.empty?
pause = Integer(options['pause'] || options[:pause] || 240)
argv = "#{ stage } deploy"
boxes.each do |box|
started_at = Time.now
command = "cap server=#{ box } #{ argv }"
spawn command
hl = HighLine.new
question = hl.color("#{ box } started successfully? (y/
n)", :cyan, :bold)
agreed = hl.agree( question, character=true )
unless agreed
logger.important "STOPPING"
abort
end
finished_at = Time.now
elapsed = finished_at - started_at
if elapsed < pause
remaining = pause - elapsed
question = hl.color("i'd prefer to wait #{ remaining } more
seconds!\ndo you want me to force deployment now? (y/n)", :red, :bold)
agreed =
begin
Timeout.timeout(remaining) do
hl.agree( question, character=true )
end
rescue Timeout::Error
true
end
unless agreed
logger.important "STOPPING"
abort
end
end
end
box = last
command = "cap server=#{ box } #{ argv }"
spawn command
end
note that, at the end of each deployment, my cap deploy runs 'rake
head' which calculates the server/port the service should be running
on and shells out a 'curl -I'. therefore i see '200 OK' etc go by in
the output and use this as the signal to continue deployment. in
english, i don't move on until i know the server is up.
a @ http://codeforpeople.com/
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama
--~--~---------~--~----~------------~-------~--~----~
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/capistrano
-~----------~----~----~----~------~----~------~--~---