2013-02-24 120 views
2

我對使用獨角獸實現零停機時間所需的內容感到困惑,更具體地說,如果它與preload_app選項無關。我知道,如果我有preload_app錯誤,我可以簡單地發送一個HUP信號,獨角獸會自動考慮新代碼,但是它會以零時間方式執行嗎?獨角獸 - 使用HUP零宕機?

此外,如果內存不是問題,我是否需要使用preload_app true?

最後,我看到很多例子,其中有一個關於oldpid的代碼之前有一個很大的代碼塊。何時需要此代碼?

謝謝

回答

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 

這將啓動新員工,並逐步關閉舊員工。

+2

但是,通過使用preload_app false併發送kill HUP,我會得到類似的行爲嗎? – allaire 2013-02-25 03:02:29