【问题标题】:Use `reload` instead of `restart` for Unicorn?独角兽使用`reload`而不是`restart`?
【发布时间】:2012-02-29 11:21:19
【问题描述】:

我对这里的部署策略有点困惑,在什么情况下部署时我想向独角兽发送reload 信号?例如,在我的情况下,它会是:

sudo kill -s USR2 `cat /home/deploy/apps/my_app/current/tmp/pids/unicorn.pid`

我一直在通过杀死该 pid 来部署我的应用程序,然后通过以下方式再次启动 unicorn:

bundle exec unicorn -c config/unicorn/production.rb -E production -D

我只是想知道为什么我要使用重新加载?这样做可以让我的部署获得任何性能吗?

【问题讨论】:

    标签: ruby unicorn


    【解决方案1】:

    当你杀死独角兽时,你会导致停机,直到独角兽可以重新启动。当你使用 USR2 信号时,独角兽首先启动新工人,然后一旦它们运行,它就会杀死旧工人。基本上都是为了消除“关闭”独角兽的需要。

    注意,假设你在你的独角兽配置中有记录的before_fork钩子,为了处理旧工人的杀戮,应该找到一个“.oldbin”文件,其中包含旧独角兽的PID进程:

    before_fork do |server, worker|
      # a .oldbin file exists if unicorn was gracefully restarted with a USR2 signal
      # we should terminate the old process now that we're up and running
      old_pid = "#{pids_dir}/unicorn.pid.oldbin"
      if File.exists?(old_pid)
        begin
          Process.kill("QUIT", File.read(old_pid).to_i)
        rescue Errno::ENOENT, Errno::ESRCH
          # someone else did our job for us
        end
      end
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-29
      • 2013-07-09
      • 2014-08-19
      • 2014-01-15
      • 2012-01-05
      • 1970-01-01
      • 2015-12-01
      相关资源
      最近更新 更多