Ruby-on-rails Capistrano 中的“角色”究竟是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1155218/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What exactly is a "role" in Capistrano?
提问by Ethan
What is the purpose and function of "roles" in a Capistrano recipe? When I look at sample recipes, I often see something like this:
Capistrano 配方中“角色”的目的和功能是什么?当我查看示例食谱时,我经常看到这样的内容:
role :app, 'somedomain.com'
role :web, 'somedomain.com'
role :db, 'somedomain.com', :primary => true
So it looks like a roleis basically a serverwhere Capistrano executes commands. If that's the case, then why would it be called a "role" rather than a "host" or "server"?
所以看起来角色基本上是Capistrano 执行命令的服务器。如果是这样,那为什么将其称为“角色”而不是“主机”或“服务器”?
In the above example, what is the difference between the :appand :webroles?
在上面的例子中,:app和:web角色之间有什么区别?
What does the :primary => trueoption do?
什么是:primary => true选择做什么?
采纳答案by codeprimate
Roles allow you to write capistrano tasks that only apply to certain servers. This really only applies to multi-server deployments. The default roles of "app", "web", and "db" are also used internally, so their presence is not optional (AFAIK)
角色允许您编写仅适用于某些服务器的 capistrano 任务。这实际上仅适用于多服务器部署。“app”、“web”和“db”的默认角色也在内部使用,因此它们的存在不是可选的(AFAIK)
In the sample you provided, there is no functional difference.
在您提供的示例中,没有功能差异。
The ":primary => true" is an attribute that allows for further granularity in specifying servers in custom tasks.
":primary => true" 是一个属性,它允许在自定义任务中指定服务器的粒度更细。
Here is an example of role specification in a task definition:
以下是任务定义中角色规范的示例:
task :migrate, :roles => :db, :only => { :primary => true } do
# ...
end
See the capistrano website @ https://github.com/capistrano/capistrano/wiki/2.x-DSL-Configuration-Roles-Rolefor a more extensive explanation.
请参阅 capistrano 网站 @ https://github.com/capistrano/capistrano/wiki/2.x-DSL-Configuration-Roles-Role以获得更广泛的解释。
回答by Bobby Wallace
The ":primary => true" option indicates that the database server is primary server. This is important for when you want to use replication with MySQL, for example. It allows you to create another mirrored database server that can be used for automatic failover. It's also used for deciding on which database server the model migrations should be run (as those changes will be replicated to the failover servers). This link clarifies it a bit more: https://github.com/capistrano/capistrano/wiki/2.x-from-the-beginning#back-to-configuration
":primary => true" 选项表示数据库服务器是主服务器。例如,当您想在 MySQL 中使用复制时,这很重要。它允许您创建另一个可用于自动故障转移的镜像数据库服务器。它还用于决定应该运行模型迁移的数据库服务器(因为这些更改将复制到故障转移服务器)。这个链接更澄清了一点:https: //github.com/capistrano/capistrano/wiki/2.x-from-the-beginning#back-to-configuration

