从 Unicorn 配置文件中引用 Rails

Nei*_*own 3 ruby-on-rails unicorn ruby-on-rails-3

我正在尝试按照这三个链接建议的行更改我的 Unicorn 配置文件,以更改 Unicorn 日志记录:

它们都遵循相同的模式(我正在尝试第一个),但是当我将它们添加到我的配置中时,我得到了 Unicorn 一遍又一遍地重复相同的消息:

ERROR -- : uninitialized constant Unicorn::Configurator::Rails (NameError)
Run Code Online (Sandbox Code Playgroud)

堆栈跟踪指向 Unicorn 日志文件中第一次使用 Rails。我做错了什么,或者我需要改变什么才能让这些片段工作?

我正在使用 Rails 3.2.14,并使用以下方法调用我的服务器:

bundle exec unicorn -c config/unicorn.rb
Run Code Online (Sandbox Code Playgroud)

使用unicorn_rails而不是unicorn没有区别(相同的错误)。我的配置是这样的:

worker_processes 20
listen ".../unicorn.socket", :backlog => 64
timeout 30
pid ...
stderr_path ...
stdout_path ...
GC.respond_to?(:copy_on_write_friendly=) and
  GC.copy_on_write_friendly = true
check_client_connection false
before_fork do |server, worker|
  # No code
end

after_fork do |server, worker|
  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.establish_connection

  # Snippet from the links above, error occurs within here
  if defined?(ActiveSupport::TaggedLogging) && Rails.logger.kind_of?(ActiveSupport::TaggedLogging)
    ...
  end
end
Run Code Online (Sandbox Code Playgroud)

Mic*_*rry 5

你需要preload_app true在你的配置中设置像 Rails 这样的 gems 才能从配置文件访问 - 请参阅此处的文档。