Capistrano 3:仅在分配了角色的服务器池中的单个服务器上运行任务 [英] Capistrano 3: Run task only on a single server from a pool of servers assigned a role

查看:65
本文介绍了Capistrano 3:仅在分配了角色的服务器池中的单个服务器上运行任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有20台处于网络角色的服务器。由于更改会影响共享存储,因此我只需要对其中一项执行任务。我当前的解决方案是解决此问题的方法(如下)。寻找更好的方法,我没有大量的红宝石或制帽经验。

I have 20 servers that are in the "web" role. I have a task I need to perform on only one of them as the change affects shared storage. My current solution is a hack to get around this (below). Looking for a better way, I don't have a ton of ruby or cap experience.

task :checkout_project_properties do
    num_runs = 0
    on roles(:web), in: :sequence do
        if num_runs > 0
            abort('Only running on one server.  Exiting')
        end
        execute("checkout-project-properties #{uc_stage} #{repo} #{branch}")
        num_runs += 1
    end
end


推荐答案

我假设您是指具有这么多Web服务器的生产配置。在这种情况下,您的 config / deploy / production.rb 可能包含许多这样的行:

I assume that you are referring to your production configuration, with so many web servers. In this case, your config/deploy/production.rb probably contains many lines like this:

server 'web_1', roles: %w(web)
server 'web_2', roles: %w(web)
server 'web_3', roles: %w(web)
...

只需将其中一台服务器设置为主服务器,因此看起来像这样:

Simply make one of these servers primary, so it looks like:

server 'web_1', roles: %w(web), primary: true
server 'web_2', roles: %w(web)
server 'web_3', roles: %w(web)
...    

然后更改您的任务,使其看起来像这样:

Then change your task so it looks like this:

task :checkout_project_properties do
    on primary(:web) do
        execute("checkout-project-properties #{uc_stage} #{repo} #{branch}")
    end
end

这篇关于Capistrano 3:仅在分配了角色的服务器池中的单个服务器上运行任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆