1 # Sample verbose configuration file for Unicorn (not Rack)
3 # This configuration file documents many features of Unicorn
4 # that may not be needed for some applications. See
5 # https://yhbt.net/unicorn/examples/unicorn.conf.minimal.rb
6 # for a much simpler configuration file.
8 # See https://yhbt.net/unicorn/Unicorn/Configurator.html for complete
11 # Use at least one worker per core if you're on a dedicated server,
12 # more will usually help for _short_ waits on databases/caches.
15 # Since Unicorn is never exposed to outside clients, it does not need to
16 # run on the standard HTTP port (80), there is no reason to start Unicorn
17 # as root unless it's from system init scripts.
18 # If running the master process as root and the workers as an unprivileged
19 # user, do this to switch euid/egid in the workers (also chowns logs):
20 # user "unprivileged_user", "unprivileged_group"
22 # Help ensure your application will always spawn in the symlinked
23 # "current" directory that Capistrano sets up.
24 working_directory "/path/to/app/current" # available in 0.94.0+
26 # listen on both a Unix domain socket and a TCP port,
27 # we use a shorter backlog for quicker failover when busy
28 listen "/path/to/.unicorn.sock", :backlog => 64
29 listen 8080, :tcp_nopush => true
31 # nuke workers after 30 seconds instead of 60 seconds (the default)
34 # feel free to point this anywhere accessible on the filesystem
35 pid "/path/to/app/shared/pids/unicorn.pid"
37 # By default, the Unicorn logger will write to stderr.
38 # Additionally, ome applications/frameworks log to stderr or stdout,
39 # so prevent them from going to /dev/null when daemonized here:
40 stderr_path "/path/to/app/shared/log/unicorn.stderr.log"
41 stdout_path "/path/to/app/shared/log/unicorn.stdout.log"
43 # combine Ruby 2.0.0+ with "preload_app true" for memory savings
46 # Enable this flag to have unicorn test client connections by writing the
47 # beginning of the HTTP headers before calling the application. This
48 # prevents calling the application for connections that have disconnected
49 # while queued. This is only guaranteed to detect clients on the same
50 # host unicorn runs on, and unlikely to detect disconnects even on a
52 check_client_connection false
54 # local variable to guard against running a hook multiple times
57 before_fork do |server, worker|
58 # the following is highly recomended for Rails + "preload_app true"
59 # as there's no need for the master process to hold a connection
60 defined?(ActiveRecord::Base) and
61 ActiveRecord::Base.connection.disconnect!
63 # Occasionally, it may be necessary to run non-idempotent code in the
64 # master before forking. Keep in mind the above disconnect! example
65 # is idempotent and does not need a guard.
67 # do_something_once_here ...
68 run_once = false # prevent from firing again
71 # The following is only recommended for memory/DB-constrained
72 # installations. It is not needed if your system can house
73 # twice as many worker_processes as you have configured.
75 # # This allows a new master process to incrementally
76 # # phase out the old master process with SIGTTOU to avoid a
77 # # thundering herd (especially in the "preload_app false" case)
78 # # when doing a transparent upgrade. The last worker spawned
79 # # will then kill off the old master process with a SIGQUIT.
80 # old_pid = "#{server.config[:pid]}.oldbin"
81 # if old_pid != server.pid
83 # sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
84 # Process.kill(sig, File.read(old_pid).to_i)
85 # rescue Errno::ENOENT, Errno::ESRCH
89 # Throttle the master from forking too quickly by sleeping. Due
90 # to the implementation of standard Unix signal handlers, this
91 # helps (but does not completely) prevent identical, repeated signals
92 # from being lost when the receiving process is busy.
96 after_fork do |server, worker|
97 # per-process listener ports for debugging/admin/migrations
98 # addr = "127.0.0.1:#{9293 + worker.nr}"
99 # server.listen(addr, :tries => -1, :delay => 5, :tcp_nopush => true)
101 # the following is *required* for Rails + "preload_app true",
102 defined?(ActiveRecord::Base) and
103 ActiveRecord::Base.establish_connection
105 # if preload_app is true, then you may also want to check and
106 # restart any other shared sockets/descriptors such as Memcached,
107 # and Redis. TokyoCabinet file handles are safe to reuse
108 # between any number of forked children (assuming your kernel
109 # correctly implements pread()/pwrite() system calls)