【问题标题】:Setting up Unicorn on Rails 4 - App Crashes在 Rails 4 上设置 Unicorn - 应用程序崩溃
【发布时间】:2014-10-23 15:02:40
【问题描述】:

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

我认为说明非常简单,但我在 mktdemo.herokuapp.com 的应用程序崩溃了。

我的 procfile 正在 heroku 仪表板上被读取,我看到独角兽出现在我的服务器上。 Heroku(下)上显示的 unicorn.rb 是否已过期?

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

【问题讨论】:

    标签: ruby-on-rails heroku unicorn


    【解决方案1】:

    您似乎没有添加rack-timeout gem。

    将其添加到您的 Gemfile:

    gem 'rack-timeout'
    

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

    【讨论】:

    • 谢谢,这行得通。但是,由于未初始化的超时变量,我的本地主机仍然崩溃。如何在 timeput.rb 中添加 if 语句以表明它仅适用于生产环境?
    • 您可以使用 if Rails.env.production? 设置超时条件
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多