gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 01:51:04 25 4
gpt4 key购买 nike

这是我在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com