2013-07-03 113 views
3

我有一臺服務器,每1分鐘與廚師一起部署。 對於重啓麒麟我發送USR2信號老師傅,然後嘗試代碼遞減老工人:如何正常重啓獨角獸?

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 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 

    # sleep 1 
end 

最後,該退出信號發送到老主人

而每一次我收到以下消息日誌:

E, [2013-07-03T10:56:19.983813 #19955] ERROR -- : retrying in 0.5 seconds (1 tries left) 
E, [2013-07-03T10:56:20.484468 #19955] ERROR -- : adding listener failed addr=0.0.0.0:3000 (in use) 
E, [2013-07-03T10:56:20.484595 #19955] ERROR -- : retrying in 0.5 seconds (0 tries left) 
E, [2013-07-03T10:56:20.985190 #19955] ERROR -- : adding listener failed addr=0.0.0.0:3000 (in use)     
/my_path/766ea02ce174c37de606c1960c498d53c5fb602b/vendor/bundle/ruby/1.9.1/gems/unicorn-4.4.0/lib/unicorn/socket_helper.rb:147:in `initialize': Address already in use - bind(2) (Errno::EADDRINUSE) 

這意味着,新的主無法啓動(我沒有看到在進程列表中的新主人),但老師傅不能被關閉和工人的數量是恆定的。

我可能以錯誤的方式做什麼? 感謝)

回答

0

我做了2個步驟來解決問題:

1)從工人的unicorn.conf.rb 2)設置最大數量刪除application_root從32到16

然後誤差消失從日誌。

1

優雅的方式來重新啓動麒麟將在Rake文件rake任務:

task :restart_server => :environment do 
    system("kill -QUIT `cat pids/unicorn.pid`") 
    system("bundle exec unicorn_rails -c ./config/unicorn.rb -D") 
end 

這裏假設該文件的路徑「unicorn.pid」,主服務器的過程中存在application_root /的PID/unicorn.pid。此路徑可以通過配置改變的PID值來改變/ unicorn.rb

pid "pids/unicorn.pid" 

此外,如果您使用的上限進行部署,確保該文件對遠程服務器寫權限和添加此文件。 gitignore,以便該文件不會覆蓋您的遠程生產和測試服務器上的本地pid值。