capistrano顺序重启 [英] capistrano sequential restarts

查看:103
本文介绍了capistrano顺序重启的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将capistrano配置为跨三台物理服务器进行部署。我想将重新启动任务配置为按顺序转到每个服务器并重新启动应用程序,而不是一次转到所有服务器的默认方式。

I have capistrano configured to deploy across three physical servers. I would like to configure the restart task to sequentially go to each server and restart the app rather than the default way of going to all servers at once.

这是当前的部署任务:

namespace :deploy do

  task :start, :roles => :app, :except => { :no_release => true } do 
    run "cd #{current_path} && bundle exec unicorn_rails -c #{current_path}/config/unicorn.rb -E #{rails_env} -D"
  end

  task :stop, :roles => :app, :except => { :no_release => true } do 
    run "kill `cat #{current_path}/tmp/pids/unicorn.pid`"
  end

  task :restart, :roles => :app, :except => { :no_release => true } do
    stop
    sleep(10)
    start
  end

end

我在想这样的事情:

#this does not work 
task :sequential_restart do
   find_servers(:roles => :app).each
    restart
   end
 end

有什么想法吗?

推荐答案

我做得非常好与 HOSTFILTER 环境变量类似,该变量有效地将所有内容限定在与过滤器匹配的主机上。

I do something very similar using the HOSTFILTER environment variable, which effectively scopes everything to the hosts matching the filter.

类似

find_servers(:roles => :app).each do |server|
  ENV['HOSTFILTER'] = server.host
  restart
end
ENV['HOSTFILTER'] = nil

应该可以解决问题。

这篇关于capistrano顺序重启的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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