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