unicorn 1.1.7 - major fixes to minor components
[unicorn.git] / examples / unicorn.conf.rb
blob37c3e81c17c7f9e5d7f890109fac5db85a366514
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 # http://unicorn.bogomips.org/examples/unicorn.conf.minimal.rb
6 # for a much simpler configuration file.
8 # See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete
9 # documentation.
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.
13 worker_processes 4
15 # Help ensure your application will always spawn in the symlinked
16 # "current" directory that Capistrano sets up.
17 working_directory "/path/to/app/current" # available in 0.94.0+
19 # listen on both a Unix domain socket and a TCP port,
20 # we use a shorter backlog for quicker failover when busy
21 listen "/tmp/.sock", :backlog => 64
22 listen 8080, :tcp_nopush => true
24 # nuke workers after 30 seconds instead of 60 seconds (the default)
25 timeout 30
27 # feel free to point this anywhere accessible on the filesystem
28 pid "/path/to/app/shared/pids/unicorn.pid"
30 # By default, the Unicorn logger will write to stderr.
31 # Additionally, ome applications/frameworks log to stderr or stdout,
32 # so prevent them from going to /dev/null when daemonized here:
33 stderr_path "/path/to/app/shared/log/unicorn.stderr.log"
34 stdout_path "/path/to/app/shared/log/unicorn.stdout.log"
36 # combine REE with "preload_app true" for memory savings
37 # http://rubyenterpriseedition.com/faq.html#adapt_apps_for_cow
38 preload_app true
39 GC.respond_to?(:copy_on_write_friendly=) and
40   GC.copy_on_write_friendly = true
42 before_fork do |server, worker|
43   # the following is highly recomended for Rails + "preload_app true"
44   # as there's no need for the master process to hold a connection
45   defined?(ActiveRecord::Base) and
46     ActiveRecord::Base.connection.disconnect!
48   # The following is only recommended for memory/DB-constrained
49   # installations.  It is not needed if your system can house
50   # twice as many worker_processes as you have configured.
51   #
52   # # This allows a new master process to incrementally
53   # # phase out the old master process with SIGTTOU to avoid a
54   # # thundering herd (especially in the "preload_app false" case)
55   # # when doing a transparent upgrade.  The last worker spawned
56   # # will then kill off the old master process with a SIGQUIT.
57   # old_pid = "#{server.config[:pid]}.oldbin"
58   # if old_pid != server.pid
59   #   begin
60   #     sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
61   #     Process.kill(sig, File.read(old_pid).to_i)
62   #   rescue Errno::ENOENT, Errno::ESRCH
63   #   end
64   # end
65   #
66   # # *optionally* throttle the master from forking too quickly by sleeping
67   # sleep 1
68 end
70 after_fork do |server, worker|
71   # per-process listener ports for debugging/admin/migrations
72   # addr = "127.0.0.1:#{9293 + worker.nr}"
73   # server.listen(addr, :tries => -1, :delay => 5, :tcp_nopush => true)
75   # the following is *required* for Rails + "preload_app true",
76   defined?(ActiveRecord::Base) and
77     ActiveRecord::Base.establish_connection
79   # if preload_app is true, then you may also want to check and
80   # restart any other shared sockets/descriptors such as Memcached,
81   # and Redis.  TokyoCabinet file handles are safe to reuse
82   # between any number of forked children (assuming your kernel
83   # correctly implements pread()/pwrite() system calls)
84 end