gpt4 book ai didi

ruby-on-rails - Rails Unicorn Web 服务器无法在 Heroku 上启动

转载 作者:行者123 更新时间:2023-12-02 03:45:48 25 4
gpt4 key购买 nike

我无法让我的应用在 Heroku 上成功启动。这是基础知识:

  • Ruby 1.9.3p392(当我在我的开发终端中运行 Ruby -v 时,这是返回的内容,但是 Heroku 日志似乎指示 Ruby 2.0.0)
  • rails 3.2.13
  • unicorn 网络服务器
  • PostgreSQL 数据库

我已将我的应用程序部署到 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__)))

这一行在开发中很有用,可以从我的 application.yml 文件中读取我的环境变量。但是,出于安全目的,我从我的存储库中 gitignore 它并且可以看到 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 指南,我安装了 Figaro,但是并没有解决问题。

如果您想查看完整的应用程序,它已发布在:https://github.com/mxstrand/mxspro

如果您对可能出现的问题或如何进一步排除故障提供指导,我将不胜感激。谢谢。

最佳答案

您的分析准确无误。我刚刚提取了您的代码,进行了一些调整,现在已经在 Heroku 上启动了。

我唯一的改变;

config/application.rb - 将第 12 和 13 行移动到 config/environments/development.rb - 如果您使用 application.yml 作为开发环境变量,那么保持这种方式。另一种选择是在第 13 行的末尾添加 if Rails.env.development? 以适应您的开发环境。

config/environments/production.rb - 第 33 行缺少前面的 # 标记

关于ruby-on-rails - Rails Unicorn Web 服务器无法在 Heroku 上启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17256708/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com