簡體   English   中英

Rails Unicorn Web Server無法在Heroku上啟動

[英]Rails Unicorn Web Server Won't Start on Heroku

我無法讓我的應用程序成功啟動Heroku。 這是基礎知識:

  • Ruby 1.9.3p392(當我在我的開發終端中運行Ruby -v時,這是返回的,但是Heroku日志似乎表示Ruby 2.0.0)
  • Rails 3.2.13
  • Unicorn Web Server
  • Postgresql DB

我已將我的應用程序部署到Heroku,但收到“應用程序中發生錯誤,無法提供您的頁面”。

這是Heroku日志中的最終條目:

+00:00 app[web.1]: from /app/vendor/bundle/ruby/2.0.0/bin/unicorn:23:in `<main>'
+00:00 heroku[web.1]: Process exited with status 1
+00:00 heroku[web.1]: State changed from starting to crashed

當我嘗試運行Heroku ps時,我得到:

=== web (1X): `bundle exec unicorn -p $PORT -c ./config/unicorn.rb`
web.1: crashed 2013/06/22 17:31:22 (~ 6m ago)

認為問題可能源於我的app / config / application.rb中的這一行

ENV.update YAML.load(File.read(File.expand_path('../application.yml', __FILE__)))

這行在dev中用於從我的application.yml文件中讀取我的環境變量。 但是,為了安全起見,我從我的倉庫中獲取它,並且可以看到Heroku日志抱怨此文件未找到。 為了生產,我通過以下方式在Heroku中設置了我的環境變量:

heroku config:add SECRET_TOKEN=a_really_long_number

這是我的app / config / unicorn.rb

# 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

這是我的Procfile

web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb

我的app / config / unicorn.rb和Procfile設置都來自https://devcenter.heroku.com/articles/rails-unicorn

根據一些IRC指導,我安裝了費加羅,但唉,但沒有解決問題。

如果你想看到完整的應用程序,它發布在: https//github.com/mxstrand/mxspro

如果您對可能出現的問題有所了解或者我可能會如何進一步排除故障,我會很感激。 謝謝。

你隨時可以看到你的分析。 我剛剛提取了你的代碼,做了一些調整,現在已經開始在Heroku上了。

我唯一的變化;

config/application.rb - 將第12和13行移動到config/environments/development.rb - 如果您正在將application.yml用於開發環境變量,那么請保持這種方式。 其他選擇是使用if Rails.env.development?使第13行以您的開發環境為if Rails.env.development? 在末尾。

config/environments/production.rb - 在#mark之前缺少第33行

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM