生产中的Unicorn undefined方法错误

时间:2014-08-08 16:03:51

标签: ruby-on-rails heroku unicorn

我使用Rails 4.1.4,Unicorn 4.8.3和Ruby 2.1.1在Heroku上运行Ruby on Rails应用程序。我试图让开发和生产环境保持相似。在开发过程中,Unicorn运行得很好。

在制作中,我在日志中得到了这个:

» 21:54:50.942 2014-08-08 01:54:50.645897+00:00 app web.2 - - /app/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:651:in `worker_loop'
» 21:54:50.942 2014-08-08 01:54:50.645898+00:00 app web.2 - - /app/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:525:in `spawn_missing_workers'
» 21:54:50.947 2014-08-08 01:54:50.645900+00:00 app web.2 - - /app/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:536:in `maintain_worker_count'
» 21:54:50.947 2014-08-08 01:54:50.645902+00:00 app web.2 - - /app/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:294:in `join'
» 21:54:50.947 2014-08-08 01:54:50.645904+00:00 app web.2 - - /app/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/bin/unicorn:126:in `<top (required)>'
» 21:54:50.947 2014-08-08 01:54:50.645905+00:00 app web.2 - - /app/vendor/bundle/ruby/2.1.0/bin/unicorn:23:in `load'
» 21:54:50.947 2014-08-08 01:54:50.645907+00:00 app web.2 - - /app/vendor/bundle/ruby/2.1.0/bin/unicorn:23:in `<main>'
» 21:54:50.947 2014-08-08 01:54:50.706442+00:00 app web.2 - - E, [2014-08-08T01:54:50.705828 #609] ERROR -- : undefined method `[]=' for nil:NilClass (NoMethodError)
» 21:54:50.947 2014-08-08 01:54:50.706451+00:00 app web.2 - - ./config/unicorn.rb:24:in `block in reload'
» 21:54:50.947 2014-08-08 01:54:50.706454+00:00 app web.2 - - /app/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:622:in `call'
» 21:54:50.958 2014-08-08 01:54:48.473529+00:00 heroku web.1 - - Error R12 (Exit timeout) -> At least one process failed to exit within 10 seconds of SIGTERM Warning
» 21:54:50.971 2014-08-08 01:54:50.665188+00:00 app web.1 - - E, [2014-08-08T01:54:50.665105 #2] ERROR -- : reaped #<Process::Status: pid 487 exit 1> worker=0
» 21:54:50.973 2014-08-08 01:54:50.722566+00:00 app web.1 - - E, [2014-08-08T01:54:50.722003 #495] ERROR -- : undefined method `[]=' for nil:NilClass (NoMethodError)
» 21:54:50.973 2014-08-08 01:54:50.722572+00:00 app web.1 - - ./config/unicorn.rb:24:in `block in reload'
» 21:54:50.973 2014-08-08 01:54:50.722574+00:00 app web.1 - - /app/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:622:in `call'
» 21:54:50.973 2014-08-08 01:54:50.722576+00:00 app web.1 - - /app/vendor/bundle/ruby/2.1.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:622:in `init_worker_process'

该应用程序几乎无法启动。我在Google搜索了undefined method `[]=' for nil:NilClass (NoMethodError)错误,此处没有任何帮助。

有什么想法吗?

1 个答案:

答案 0 :(得分:3)

我能够通过更新unicorn.rb配置文件的一部分来解决这个问题。

来自:

config = Rails.application.config.database_configuration[Rails.env]

要:

config = ActiveRecord::Base.configurations[Rails.env] || Rails.application.config.database_configuration[Rails.env]

我使用的是过时的代码。 Source