Created
December 3, 2014 20:25
-
-
Save hobodave/cb81e90ffc26e0a8d792 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
after_fork do |server, worker| | |
port = 5000 + worker.nr | |
child_pid = server.config[:pid].sub('.pid', ".#{port}.pid") | |
system("echo #{Process.pid} > #{child_pid}") | |
defined?(ActiveRecord::Base) and | |
ActiveRecord::Base.establish_connection | |
#one log per unicorn worker | |
filepath = "#{root}/log/#{Rails.env}.#{worker.nr}.log" | |
f = File.open filepath, 'a' | |
f.binmode | |
f.sync = true | |
Rails.logger.instance_eval do | |
level = @logger.level | |
@logger && @logger.flush && @logger.close | |
@logger = ActiveSupport::BufferedLogger.new(f, level) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment