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