我使用普通的capistrano来部署一个在node中编写的简单集群。
我对角色的定义如下:

role :boss, "bosshost"
role :worker, { get_worker_hosts }

我使用capistrano的默认deploy dance+own任务将worker应用程序放到服务器上。
问题是,我不想为boss使用这些脚本,因为它只是一个脚本。理想的情况是:
namespace :boss
  task :update, :roles => [:boss]
    upload 'boss.js', "#{boss_home}/boss.js"
  end
  task :restart, :roles => [:boss]
    run "forever restart #{boss_home}/boss.js"
  end
end

我在:roles => [:worker]之后发生的所有与工人相关的任务中都使用了deploy:finalize_update。但是,运行$ cap deploy仍然会在boss服务器上放置不成功的内容。
我如何告诉Capistranodeploy任务和以下默认任务应该只为worker角色的服务器运行?

最佳答案

我自己也能搞清楚。在我的特定情况下,由于应用程序群集正在使用nfs装载,我只需要将应用程序部署到一个服务器上,但在部署完成后,我需要重新启动应用程序群集中所有服务器上的节点守护程序。
我的解决方案是为每台服务器设置角色(您也可以使用role):

server 'a-server.com', :app, :web, :service
server 'another-server.com', :service, :no_release => true

关键是:no_release => true这样代码就不会部署到此服务器。内置任务将遵循这一准则,我也有几个自定义任务。我通过查看并行运行的任务的部署输出并添加以下内容来解决自定义任务:
task "my_task", :except => { :no_release => true } do
  # do stuff here...
  # Example of using a role with `run`
  run "sudo /etc/init.d/nodejs-#{application} restart", :roles => :service
end

希望能有帮助!

10-08 04:37