2012-09-07 31 views
4

任何人都可以闡明這個錯誤究竟是指什麼?Rails,Capistrano,Nginx,Unicorn - 應用程序已經初始化(RuntimeError)

我在部署網站的新版本時遇到問題。

I, INFO -- : reloading config_file=[snip]/current/config/unicorn.rb 
I, INFO -- : Refreshing Gem list 
E, ERROR -- : error reloading config_file=[snip]/current/config/unicorn.rb: Application has been already initialized. (RuntimeError) 
E, ERROR -- : [snip]/shared/bundle/ruby/1.9.1/gems/railties-3.2.3/lib/rails/application.rb:135:in `initialize!' 
E, ERROR -- : [snip]/shared/bundle/ruby/1.9.1/gems/railties-3.2.3/lib/rails/railtie/configurable.rb:30:in `method_missing' 
E, ERROR -- : [snip]/releases/20120907085937/config/environment.rb:5:in `<top (required)>' 
E, ERROR -- : [snip]/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require' 
E, ERROR -- : [snip]/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `block in require' 
E, ERROR -- : [snip]/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:in `load_dependency' 
E, ERROR -- : [snip]/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require' 
E, ERROR -- : config.ru:4:in `block in <main>' 
E, ERROR -- : [snip]/shared/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval' 
E, ERROR -- : [snip]/shared/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize' 
E, ERROR -- : config.ru:1:in `new' 
E, ERROR -- : config.ru:1:in `<main>' 
E, ERROR -- : [snip]/shared/bundle/ruby/1.9.1/gems/unicorn-4.3.1/lib/unicorn.rb:44:in `eval' 
E, ERROR -- : [snip]/shared/bundle/ruby/1.9.1/gems/unicorn-4.3.1/lib/unicorn.rb:44:in `block in builder' 
E, ERROR -- : [snip]/shared/bundle/ruby/1.9.1/gems/unicorn-4.3.1/lib/unicorn/http_server.rb:696:in `call' 
E, ERROR -- : [snip]/shared/bundle/ruby/1.9.1/gems/unicorn-4.3.1/lib/unicorn/http_server.rb:696:in `build_app!' 
E, ERROR -- : [snip]/shared/bundle/ruby/1.9.1/gems/unicorn-4.3.1/lib/unicorn/http_server.rb:677:in `load_config!' 
E, ERROR -- : [snip]/shared/bundle/ruby/1.9.1/gems/unicorn-4.3.1/lib/unicorn/http_server.rb:303:in `join' 
E, ERROR -- : [snip]/shared/bundle/ruby/1.9.1/gems/unicorn-4.3.1/bin/unicorn:121:in `<top (required)>' 
E, ERROR -- : [snip]/shared/bundle/ruby/1.9.1/bin/unicorn:23:in `load' 
E, ERROR -- : [snip]/shared/bundle/ruby/1.9.1/bin/unicorn:23:in `<main>' 
I, INFO -- : reaped #<Process::Status: pid 3182 exit 0> worker=0 
I, INFO -- : reaped #<Process::Status: pid 3185 exit 0> worker=1 
I, INFO -- : reaped #<Process::Status: pid 3188 exit 0> worker=2 
I, INFO -- : reaped #<Process::Status: pid 3191 exit 0> worker=3 
I, INFO -- : worker=0 ready 
I, INFO -- : worker=3 ready 
I, INFO -- : worker=1 ready 
I, INFO -- : worker=2 ready 

Unicorn.rb

root = "/home/[user]/apps/[site]/current" 
working_directory root 
pid "#{root}/tmp/pids/unicorn.pid" 
stderr_path "#{root}/log/unicorn.log" 
stdout_path "#{root}/log/unicorn.log" 

listen "/tmp/unicorn.[site].sock", :backlog => 2048 

worker_processes 4 

preload_app true 

timeout 30 

before_fork do |server, worker| 
    defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect! 
end 

after_fork do |server, worker| 
    defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection 
end 

任何幫助表示讚賞 - 如果需要的話我可以拉更多的配置文件。

+0

也許這個話題會幫助你http://tutorruby.com/question/show/id/3237我提交th是作爲評論,因爲我不確定它是相關的。 – dennis

+0

從Capistrano部署時,何時發生此錯誤?獨角獸如何處理新的部署?你能分享你的Capistrano配置嗎? – mguymon

+0

您還可以分享/releases/20120907085937/config/environment.rb嗎? – tommasop

回答

7

終於到了這個底部。在重新閱讀Ryan Bates' Railscasts episode on zero downtime deployment之後,我注意到我發佈了帶HUP而不是USR2的獨角獸重啓/重載命令。在改變這一點,並重新啓用ginettev答案中的代碼(以前我曾嘗試瞭解這個問題已被禁用,現在我可以按我的意願部署)。

更改和更改我的unicorn_init一樣簡單。 SH文件來自:

restart|reload) 
sig HUP && echo reloaded OK && exit 0 
echo >&2 "Couldn't reload, starting '$CMD' instead" 
run "$CMD" 
;; 

restart|reload) 
sig USR2 && echo reloaded OK && exit 0 
echo >&2 "Couldn't reload, starting '$CMD' instead" 
run "$CMD" 
;; 

希望這有助於別人

1

看着這爲我工作,在before_fork部分麒麟配置可能你嘗試加入以下代碼

old_pid = '#{root}/tmp/pids/unicorn.pid.oldbin' 
if File.exists?(old_pid) && server.pid != 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 

而且,你不需要檢查的ActiveRecord :: Base的是否在配置定義。

相關問題