加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

ruby-on-rails – 使用capistrano重新启动Rails应用程序的Nginx

发布时间:2020-12-13 21:05:45 所属栏目:Nginx 来源:网络整理
导读:对于我的生活,我无法弄清楚如何使这项工作正常. 问题类似于其他人的问题,例如:How to do a rolling restart of a cluster of mongrels 但是,我们使用的是Nginx / Passenger而不是Mongrel. 如果我们使用此标准,问题是在部署时:重启任务: task :restart,:ro

对于我的生活,我无法弄清楚如何使这项工作正常.

问题类似于其他人的问题,例如:How to do a rolling restart of a cluster of mongrels

但是,我们使用的是Nginx / Passenger而不是Mongrel.

如果我们使用此标准,问题是在部署时:重启任务:

task :restart,:roles => [:app],:except => {:no_release => true} do
  run "cd #{deploy_to}/current && touch tmp/restart.txt"
end

它触及每个Web服务器上的restart.txt文件,但是当前正在提供请求的任何乘客实例都需要在新的生成之前完成.这会造成严重的延迟并导致我们的应用程序在最多2分钟内无法使用,而所有内容都会重新启动.

为了解决这个问题,计划是做以下事情:

>部署代码
>转到服务器1,将其从负载均衡器中删除
>在服务器1上重启nginx-passenger
>等待60秒
>将服务器1添加回负载均衡器
>转到服务器2(重复步骤3 – 5)

为了做到这一点,我尝试了这个:

(lb.txt是负载均衡器查找的文件)

task :restart,:except => {:no_release => true} do
  servers = find_servers_for_task(current_task)
  servers.map do |s|
    run "cd #{deploy_to}/current && echo '' > public/lb.txt",:host => s.host
    run %Q{rvmsudo /etc/init.d/nginx-passenger restart > /dev/null},:host => s.host
    sleep 60
    run "cd #{deploy_to}/current && echo 'ok' > public/lb.txt",:host => s.host
  end
end

这几乎可行,但是,在部署期间,它似乎在:app角色中列出的每个服务器上运行一次通过服务器的循环.我们目前有6个app服务器,因此循环运行6次,每个服务器重启nginx-passenger 6次.

我只需要这个循环就可以运行一次.

我知道似乎最终乘客会重新开始,但它们似乎还不存在.

如果它有帮助,我们使用Capistrano 2.x和Rails 3

任何帮助都会很棒.

谢谢.

最佳答案
run "cd #{deploy_to}/current && echo 'ok' > public/lb.txt",:host => s.host

应该是:

run "cd #{deploy_to}/current && echo 'ok' > public/lb.txt",:hosts => s.host

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读