Capistrano 中具有属性(?)的多个角色
如何将属性传递给 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我用它来串行而不是并行地重新启动我的服务器。
I use this to restart my servers in series, instead of in parallel.
Justin,很抱歉这是不可能的,一旦打开流池(首先在服务器集上运行),就无法访问服务器属性。 (因为
run
代码不是在每个服务器上运行,而是针对池中的所有匹配运行)。有些人在做类似的事情上取得了一些成功,但实际上这是一个症状,您的脚本需要太多的信息,而您应该能够从生产环境中提取这些信息。在这种情况下,您似乎正在做类似使用主机名传递给脚本之类的事情,请使用 Unix 为您提供的内容:
这可行吗?
参考文献:
• 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 therun
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:
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)
没有人知道吗?我发现了一些关于下面的顺序块的信息,但据我所知......
我发现很难相信没有人需要用 cap 来执行顺序任务。
No one knows? I found something about the sequential block below, but thats as far as I got...
I find it hard to believe that no one has ever needed to do sequential tasks with cap.