开发者

Multiple roles with attributes(?) in Capistrano

开发者 https://www.devze.com 2022-12-26 17:05 出处:网络
How can I pass along attributes to my tasks in capistrano? My goal is to deploy to multiple servers in a load balancer. I\'d like to take each one out, deploy, and add it back in sequentially so no m

How can I pass along attributes to my tasks in capistrano?

My goal is to deploy to multiple servers in a load balancer. I'd like to take each one out, deploy, and add it back in sequentially so no more than one server is down at any time.

I'm thinking it would be something along the lines of... (and the hosts array would be generated dynamically after querying my load balancer)...

role :app, 
       [["server_one", {:instanceId => "alice"}], 
        ["server_two", {:instanceId => "bob"}],
        ["server_three", {:instanceId => "charles"}]]

And then for my tasks...

before :deploy, :deregister_instance_from_lb
after :deploy, :register_instance_with_lb

task deregister_instance_from_l开发者_如何学Cb
  #TODO - Deregister #{instanceId} from load balancer
end

task register_instance_with_lb
  #TODO - Register #{instanceId} with load balancer
end

Any ideas?


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


Justin, I'm sorry that's not possible, once the stream pool is opened (first run on a server set) there's no way to access server properties. (as the run code isn't run per-server, but against all-matching in the pool). Some people have had some success with doing something like this, but really it's a symptom that your scripts need too much information that you should be able to extract from your production environment.

As in this case it seems you are doing something like using the host's name to pass to a script, use what Unix gives you:

run "./my_script.rb `hostname`"

WIll that work?

References:

• http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_04.html (Section 3.4.5)

• http://unixhelp.ed.ac.uk/CGI/man-cgi?hostname (or $ man (1) hostname)


No one knows? I found something about the sequential block below, but thats as far as I got...

find_servers.each do |server|
  #TODO - remove from load balancer
  #TODO - deploy
  #TODO - add back to load balancer
end

I find it hard to believe that no one has ever needed to do sequential tasks with cap.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号