ruby-on-rails - 如何创建角色并为特定角色运行 Capistrano 任务?

标签 ruby-on-rails ruby-on-rails-4 capistrano roles role

这是我在 config/deploy 中的 production.rb

Instance Details
server '198.61.179.237', :web, :app, :db, primary: true
server '198.61.228.160', :file_server

# Rails Environment
set :rails_env, 'production'

来自 deploy.rb

namespace :check do
  task :function_1, :roles => :web do
    puts 'function_1'
  end
  task :function_2, :roles => :file_server do
    puts 'filesssss'
  end
end

但是当我尝试做的时候

cap HOSTS=198.61.228.160 production check:function_2
cap HOSTS=198.61.228.160 production check:function_1

cap HOSTS=198.61.179.237 production check:function_2
cap HOSTS=198.61.179.237 production check:function_1

他们每个人都给出了各自的输出。但根据声明

function_1 应该只对 :role => :web 有效,同样 function_2 应该只对 :role => 有效:文件服务器

我哪里错了? 什么是正确的接近方式?

最佳答案

我相信你想要的是 cap HOSTFILTER=198.61.228.160 function_2cap HOSTFILTER=198.61.179.237 function_1

这是因为 HOSTFILTER 检查所有具有函数角色的服务器和您要查找的服务器的交集。可以找到很好的解释 here通过 Pete Hodgson

我们也可以从手册中看到这一点:

    $ cap -H

       HOSTS
            Execute the tasks against this comma-separated list of hosts.
            Effectively, this makes the host(s) part of every roles.

       HOSTFILTER
            Execute tasks against this comma-separated list of host, 
            but only if the host has the proper role for the task.

       HOSTROLEFILTER
            Execute tasks against the hosts in this comma-separated list of roles,
            but only if the host has the proper role for the task.

       ROLES
            Execute tasks against this comma-separated list of roles.  Hosts which
            do not have the right roles will be skipped.

关于ruby-on-rails - 如何创建角色并为特定角色运行 Capistrano 任务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22628208/

相关文章:

ruby-on-rails - 接受属性的字符串输入,在数据库中存储整数,在 API 中返回字符串

ruby-on-rails - 如何在S3中存储数据并允许用户使用rails API/iOS客户端以安全的方式访问?

ruby-on-rails - ActiveRecord::UnknownAttributeError in UserController#create

ruby-on-rails - 在 production.rb 中禁用 eager_load 对性能有何影响?

ruby-on-rails - 时间点 : within an hour, 是在今天、明天晚于明天还是已经过去了?

ubuntu - EC2 Ubuntu Capistrano 问题(NoMethodError : undefined method `each' for "publickey":String)

ruby-on-rails - Capistrano 部署 -- Net::SSH::AuthenticationFailed -- AWS EC2

ruby-on-rails-5 - 未找到 Rails list 文件(使用 Capistrano 部署)

ruby-on-rails - Active_Admin gem 出现错误 "different prefix:"

ruby-on-rails - 如何从 has_many :through relations with :uniq => true 获取行数