卡皮斯特拉诺的“角色”到底是什么?

Capistrano 食谱中“角色”的目的和作用是什么?当我查看样品食谱时,我经常看到这样的东西:

role :app, 'somedomain.com'
role :web, 'somedomain.com'
role :db,  'somedomain.com', :primary => true

因此,看起来 角色基本上就是 Capistrano 执行命令的 服务器。如果是这样的话,那么为什么它被称为“ role”而不是“ host”或“ server”呢?

在上面的例子中,:app:web角色之间的区别是什么?

:primary => true选项有什么作用?

26721 次浏览

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)

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.

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-Role for a more extensive explanation.

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