Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referring to Rails from the Unicorn config file

I'm trying to make a change to my Unicorn config file, along the lines suggested by these three links, to alter the Unicorn logging:

  • http://pivotallabs.com/how-to-split-up-rails-3-x-by-unicorn-workers/
  • How to make each unicorn worker of my Rails application log to a different file?
  • https://gist.github.com/mudge/5063930

They all follow the same sort of pattern (I'm trying the first one), but when I add them to my config I get the same message repeated over and over by Unicorn:

ERROR -- : uninitialized constant Unicorn::Configurator::Rails (NameError)

The stack trace points to the first use of Rails in the Unicorn log file. What am I doing it wrong, or what do I need to change to get those snippets to work?

I am using Rails 3.2.14, and invoking my server using:

bundle exec unicorn -c config/unicorn.rb

Using unicorn_rails instead of unicorn makes no difference (same error). My config looks like this:

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
like image 954
Neil Brown Avatar asked Nov 27 '25 06:11

Neil Brown


1 Answers

You need to set preload_app true in your config for the gems like Rails to be accessible from the config file - see here for the documentation.

like image 178
Michael Berry Avatar answered Nov 28 '25 22:11

Michael Berry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!