简体   繁体   English

Rails Unicorn Web Server无法在Heroku上启动

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

I can't get my app to successfully start at Heroku. 我无法让我的应用程序成功启动Heroku。 Here's the basics: 这是基础知识:

  • Ruby 1.9.3p392 (when I run Ruby -v in my dev terminal this is what is returned, however the Heroku logs seem to indicate Ruby 2.0.0) Ruby 1.9.3p392(当我在我的开发终端中运行Ruby -v时,这是返回的,但是Heroku日志似乎表示Ruby 2.0.0)
  • Rails 3.2.13 Rails 3.2.13
  • Unicorn Web Server Unicorn Web Server
  • Postgresql DB Postgresql DB

I have deployed my app to Heroku but getting "An error occurred in the application and your page could not be served." 我已将我的应用程序部署到Heroku,但收到“应用程序中发生错误,无法提供您的页面”。

Here's the final entries in the Heroku log: 这是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

When I try to run Heroku ps, I get: 当我尝试运行Heroku ps时,我得到:

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

I think it's possible the problem is stemming from this line in my app/config/application.rb 认为问题可能源于我的app / config / application.rb中的这一行

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

This line is useful in dev to read my environment variables from my application.yml file. 这行在dev中用于从我的application.yml文件中读取我的环境变量。 However, for security purposes I gitignore it from my repo and can see the Heroku logs complain that this file not being found. 但是,为了安全起见,我从我的仓库中获取它,并且可以看到Heroku日志抱怨此文件未找到。 For production, I have set my environment variables at Heroku via: 为了生产,我通过以下方式在Heroku中设置了我的环境变量:

heroku config:add SECRET_TOKEN=a_really_long_number

Here's my app/config/unicorn.rb 这是我的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

And here's my Procfile 这是我的Procfile

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

Both my app/config/unicorn.rb and Procfile settings come from https://devcenter.heroku.com/articles/rails-unicorn 我的app / config / unicorn.rb和Procfile设置都来自https://devcenter.heroku.com/articles/rails-unicorn

Based on some IRC guidance, I installed Figaro, but alas that did not resolve the issue. 根据一些IRC指导,我安装了费加罗,但唉,但没有解决问题。

If you want to see the full app, it's posted at: https://github.com/mxstrand/mxspro 如果你想看到完整的应用程序,它发布在: https//github.com/mxstrand/mxspro

If you have guidance on what might be wrong or how I might troubleshoot further I'd appreciate it. 如果您对可能出现的问题有所了解或者我可能会如何进一步排除故障,我会很感激。 Thank you. 谢谢。

You're spot on with you analysis. 你随时可以看到你的分析。 I've just pulled your code, made some tweaks and now have it started on Heroku. 我刚刚提取了你的代码,做了一些调整,现在已经开始在Heroku上了。

My only changes; 我唯一的变化;

config/application.rb - moved lines 12 & 13 to config/environments/development.rb - if you're using application.yml for development environment variables then keep it that way. config/application.rb - 将第12和13行移动到config/environments/development.rb - 如果您正在将application.yml用于开发环境变量,那么请保持这种方式。 Other option is to make line 13 conditional to your development environment with if Rails.env.development? 其他选择是使用if Rails.env.development?使第13行以您的开发环境为if Rails.env.development? at the end. 在末尾。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM