2012-02-29 46 views
5

我在這裏部署策略的時候有點困惑,在什麼情況下我想發送一個reload信號給獨角獸?例如,在我的情況下,它會像:對Unicorn使用`reload`而不是`restart`?

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

我只是想知道爲什麼:

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

我被再次殺死PID,然後開始通過麒麟像部署我的應用我想要使​​用重新加載?通過這樣做我可以獲得我部署的任何性能嗎?

回答

14

當你殺死獨角獸時會導致停機,直到獨角獸開始備份。當你使用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