summaryrefslogtreecommitdiff
path: root/config/unicorn.rb.example.development
blob: f31df66015a86b0e0a0fba13430fef0befdc96fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
worker_processes 2
timeout 60

preload_app true
check_client_connection false

before_fork do |server, worker|
  # the following is highly recommended for Rails + "preload_app true"
  # as there's no need for the master process to hold a connection
  defined?(ActiveRecord::Base) &&
    ActiveRecord::Base.connection.disconnect!

  if /darwin/ =~ RUBY_PLATFORM
    require 'fiddle'

    # Dynamically load Foundation.framework, ~implicitly~ initialising
    # the Objective-C runtime before any forking happens in Unicorn
    #
    # From https://bugs.ruby-lang.org/issues/14009
    Fiddle.dlopen '/System/Library/Frameworks/Foundation.framework/Foundation'
  end
end

after_fork do |server, worker|
  # Unicorn clears out signals before it forks, so rbtrace won't work
  # unless it is enabled after the fork.
  require 'rbtrace' if ENV['ENABLE_RBTRACE']

  # the following is *required* for Rails + "preload_app true",
  defined?(ActiveRecord::Base) &&
    ActiveRecord::Base.establish_connection
end