在Rails 4上设置Unicorn - 应用程序崩溃

时间:2014-10-23 15:02:41

标签: ruby-on-rails heroku unicorn

我试图在Rails 4 / Ruby 2.0应用程序上安装unicorn。我使用heroku here上的说明进行设置。

我认为说明非常简单,但我在mktdemo.herokuapp.com的申请崩溃了。

我的procfile正在读取,所以在heroku仪表板上,我看到独角兽出现在我的服务器上。 unokuorn.rb是否在heroku(下方)上显示为过时?

在unicorn.rb中,有一个ENV [WEB_CONCURRENCY]变量。我需要将它放在yml文件中吗?我没有看到它在任何地方提到过。

我在我的应用上安装了delayed_jobs,因此我不确定这是否与它有任何关系。

#gemfile
gem 'unicorn'

#procfile
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
worker: bundle exec rake jobs:work

#config/unicorn.rb
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
timeout 15
preload_app true

before_fork do |server, worker|
  Signal.trap 'TERM' do
    puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
    Process.kill 'QUIT', Process.pid
  end

  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.connection.disconnect!
end

after_fork do |server, worker|
  Signal.trap 'TERM' do
    puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
  end

  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.establish_connection
end

# config/initializers/timeout.rb
Rack::Timeout.timeout = 10  # seconds

以下是我日志中的最后50行:

←[36m2014-10-23T02:42:30.064512+00:00 app[web.1]:←[0m   from /app/vendor/bundle/
ruby/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:54:in `run_initializer
s'
←[36m2014-10-23T02:42:30.064346+00:00 app[web.1]:←[0m   from /app/vendor/ruby-2.
0.0/lib/ruby/2.0.0/
tsort.rb:210:in `block (2 levels) in each_strongly_connected_component_from'
←[36m2014-10-23T02:42:30.064449+00:00 app[web.1]:←[0m   from /app/vendor/ruby-2.
0.0/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'
←[36m2014-10-23T02:42:30.064465+00:00 app[web.1]:←[0m   from /app/vendor/ruby-2.
0.0/lib/ruby/2.0.0/tsort.rb:180:in `each'
←[36m2014-10-23T02:42:30.064481+00:00 app[web.1]:←[0m   from /app/vendor/ruby-2.
0.0/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'
←[36m2014-10-23T02:42:30.064558+00:00 app[web.1]:←[0m   from /app/vendor/bundle/
ruby/2.0.0/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:30:in `method_m
issing'
←[36m2014-10-23T02:42:30.064427+00:00 app[web.1]:←[0m   from /app/vendor/ruby-2.
0.0/lib/ruby/2.0.0/tsort.rb:203:in `each_strongly_connected_component_from'
←[36m2014-10-23T02:42:30.064608+00:00 app[web.1]:←[0m   from config.ru:4:in `blo
ck in <main>'
←[36m2014-10-23T02:42:30.064528+00:00 app[web.1]:←[0m   from /app/vendor/bundle/
ruby/2.0.0/gems/railties-4.0.0/lib/rails/application.rb:215:in `initialize!'
←[36m2014-10-23T02:42:30.064591+00:00 app[web.1]:←[0m   from config.ru:4:in `req
uire'
←[36m2014-10-23T02:42:30.064496+00:00 app[web.1]:←[0m   from /app/vendor/ruby-2.
0.0/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
←[36m2014-10-23T02:42:30.064575+00:00 app[web.1]:←[0m   from /app/config/environ
ment.rb:5:in `<top (required)>'
←[36m2014-10-23T02:42:30.064877+00:00 app[web.1]:←[0m   from /app/vendor/bundle/
ruby/2.0.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:764:in `build_app!'
←[36m2014-10-23T02:42:30.064790+00:00 app[web.1]:←[0m   from config.ru:1:in `new
'
←[36m2014-10-23T02:42:30.064892+00:00 app[web.1]:←[0m   from /app/vendor/bundle/
ruby/2.0.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:137:in `start'
←[36m2014-10-23T02:42:30.064767+00:00 app[web.1]:←[0m   from /app/vendor/bundle/
ruby/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
←[36m2014-10-23T02:42:30.064630+00:00 app[web.1]:←[0m   from /app/vendor/bundle/
ruby/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
←[36m2014-10-23T02:42:30.064924+00:00 app[web.1]:←[0m   from /app/vendor/bundle/
ruby/2.0.0/gems/unicorn-4.8.3/bin/unicorn:126:in `<top (required)>'
←[36m2014-10-23T02:42:30.064940+00:00 app[web.1]:←[0m   from /app/vendor/bundle/
ruby/2.0.0/bin/unicorn:23:in `load'
←[36m2014-10-23T02:42:30.064830+00:00 app[web.1]:←[0m   from /app/vendor/bundle/
ruby/2.0.0/gems/unicorn-4.8.3/lib/unicorn.rb:48:in `eval'
←[36m2014-10-23T02:42:30.064861+00:00 app[web.1]:←[0m   from /app/vendor/bundle/
ruby/2.0.0/gems/unicorn-4.8.3/lib/unicorn/http_server.rb:764:in `call'
←[36m2014-10-23T02:42:30.064956+00:00 app[web.1]:←[0m   from /app/vendor/bundle/
ruby/2.0.0/bin/unicorn:23:in `<main>'
←[36m2014-10-23T02:42:30.064814+00:00 app[web.1]:←[0m   from config.ru:1:in `<ma
in>'
←[36m2014-10-23T02:42:30.064846+00:00 app[web.1]:←[0m   from /app/vendor/bundle/
ruby/2.0.0/gems/unicorn-4.8.3/lib/unicorn.rb:48:in `block in builder'
←[36m2014-10-23T02:42:30.897477+00:00 heroku[web.1]:←[0m State changed from star
ting to crashed
←[36m2014-10-23T02:42:30.888021+00:00 heroku[web.1]:←[0m Process exited with sta
tus 1
←[33m2014-10-23T02:44:47.509030+00:00 heroku[router]:←[0m at=error code=H10 desc
="App crashed" method=GET path="/" host=mktdemo.herokuapp.com request_id=6472e28
f-4ba3-4eed-aa0d-8089c0ddcec4 fwd="67.180.31.102" dyno= connect= service= status
=503 bytes=
←[33m2014-10-23T02:51:07.861451+00:00 heroku[router]:←[0m at=error code=H10 desc
="App crashed" method=GET path="/" host=mktdemo.herokuapp.com request_id=c792113
3-fdbd-4614-8425-c90115aa2251 fwd="74.86.158.106" dyno= connect= service= status
=503 bytes=
←[33m2014-10-23T03:05:42.246318+00:00 heroku[router]:←[0m at=error code=H10 desc
="App crashed" method=GET path="/favicon.ico" host=mktdemo.herokuapp.com request
_id=ca8a9d59-9764-4f1c-8b8d-15845c73146e fwd="67.180.31.102" dyno= connect= serv
ice= status=503 bytes=
←[33m2014-10-23T03:05:41.930425+00:00 heroku[router]:←[0m at=error code=H10 desc
="App crashed" method=GET path="/" host=mktdemo.herokuapp.com request_id=dd9b869
8-57c5-4465-810e-f55de098df5e fwd="67.180.31.102" dyno= connect= service= status
=503 bytes=

1 个答案:

答案 0 :(得分:1)

您似乎没有添加rack-timeout宝石。

将其添加到您的Gemfile:

gem 'rack-timeout'

然后运行bundle install,检查更新的Gemfile和Gemfile.lock,并将更改推送到Heroku。