Capistrano 中具有属性(?)的多个角色

发布于 2024-08-28 17:54:52 字数 680 浏览 9 评论 0原文

如何将属性传递给 Capistrano 中的任务?

我的目标是部署到负载均衡器中的多个服务器。我想将每台服务器取出、部署并按顺序添加回来,这样任何时候都不会有超过一台服务器出现故障。

我认为这将类似于...(主机数组将在查询我的负载均衡器后动态生成)...

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

然后对于我的任务...

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

task deregister_instance_from_lb
  #TODO - Deregister #{instanceId} from load balancer
end

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

有什么想法吗?

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_lb
  #TODO - Deregister #{instanceId} from load balancer
end

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

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

生寂 2024-09-04 17:54:52

我用它来串行而不是并行地重新启动我的服务器。

task :my_task, :roles => :web do
  find_servers_for_task(current_task).each do |server|
    run "[task command here]", :hosts => server.host
  end
end

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
呢古 2024-09-04 17:54:52

Justin,很抱歉这是不可能的,一旦打开流池(首先在服务器集上运行),就无法访​​问服务器属性。 (因为 run 代码不是在每个服务器上运行,而是针对池中的所有匹配运行)。有些人在做类似的事情上取得了一些成功,但实际上这是一个症状,您的脚本需要太多的信息,而您应该能够从生产环境中提取这些信息。

在这种情况下,您似乎正在做类似使用主机名传递给脚本之类的事情,请使用 Unix 为您提供的内容:

run "./my_script.rb `hostname`"

这可行吗?

参考文献:

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

http://unixhelp.ed.ac.uk/CGI/man-cgi?hostname (或 $ man (1) 主机名)

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)

装迷糊 2024-09-04 17:54:52

没有人知道吗?我发现了一些关于下面的顺序块的信息,但据我所知......

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

我发现很难相信没有人需要用 cap 来执行顺序任务。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文