2

我对独角兽零停机所需的条件感到困惑,更具体地说,如果它与 preload_app 选项无关。我知道如果我的 preload_app 为 false,我可以简单地发送一个 HUP 信号,然后 unicorn 会自动考虑新代码,但它会以零停机时间的方式进行吗?

另外,如果内存不是问题,我是否需要使用 preload_app true ?

最后,我看到很多例子,其中有一个大的 fork 块,其中包含有关 oldpid 的代码。何时需要此代码?

谢谢

4

1 回答 1

0

我设置它的方式是kill -USR2 $(cat /path/to/unicorn.pid)在重新启动独角兽服务器时使用类似的东西,在我的独角兽服务器配置中,类似这样的东西(基于http://unicorn.bogomips.org/examples/unicorn.conf.rb):

# feel free to point this anywhere accessible on the filesystem
pid "#{shared_path}/pids/unicorn.pid"
before_fork do |server, worker|
  # the following is highly recomended for Rails + "preload_app true"
  # as there's no need for the master process to hold a connection
  defined?(ActiveRecord::Base) and
  ActiveRecord::Base.connection.disconnect!

  # This allows a new master process to incrementally
  # phase out the old master process with SIGTTOU to avoid a
  # thundering herd (especially in the "preload_app false" case)
  # when doing a transparent upgrade. The last worker spawned
  # will then kill off the old master process with a SIGQUIT.
  old_pid = "#{server.config[:pid]}.oldbin"
  if old_pid != server.pid
    begin
      sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
      Process.kill(sig, File.read(old_pid).to_i)
    rescue Errno::ENOENT, Errno::ESRCH
    end
  end
end

这将启动新工人并逐渐关闭旧工人。

于 2013-02-25T02:56:44.897 回答