unicorn.rb 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. worker_processes 8
  2. listen "/tmp/.sock", :backlog => 256
  3. preload_app true
  4. GC.respond_to?(:copy_on_write_friendly=) and
  5. GC.copy_on_write_friendly = true
  6. before_fork do |server, worker|
  7. # the following is highly recomended for Rails + "preload_app true"
  8. # as there's no need for the master process to hold a connection
  9. defined?(ActiveRecord::Base) and
  10. ActiveRecord::Base.connection.disconnect!
  11. # The following is only recommended for memory/DB-constrained
  12. # installations. It is not needed if your system can house
  13. # twice as many worker_processes as you have configured.
  14. #
  15. # # This allows a new master process to incrementally
  16. # # phase out the old master process with SIGTTOU to avoid a
  17. # # thundering herd (especially in the "preload_app false" case)
  18. # # when doing a transparent upgrade. The last worker spawned
  19. # # will then kill off the old master process with a SIGQUIT.
  20. # old_pid = "#{server.config[:pid]}.oldbin"
  21. # if old_pid != server.pid
  22. # begin
  23. # sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
  24. # Process.kill(sig, File.read(old_pid).to_i)
  25. # rescue Errno::ENOENT, Errno::ESRCH
  26. # end
  27. # end
  28. #
  29. # Throttle the master from forking too quickly by sleeping. Due
  30. # to the implementation of standard Unix signal handlers, this
  31. # helps (but does not completely) prevent identical, repeated signals
  32. # from being lost when the receiving process is busy.
  33. # sleep 1
  34. end
  35. after_fork do |server, worker|
  36. # per-process listener ports for debugging/admin/migrations
  37. # addr = "127.0.0.1:#{9293 + worker.nr}"
  38. # server.listen(addr, :tries => -1, :delay => 5, :tcp_nopush => true)
  39. # the following is *required* for Rails + "preload_app true",
  40. defined?(ActiveRecord::Base) and
  41. ActiveRecord::Base.establish_connection
  42. # if preload_app is true, then you may also want to check and
  43. # restart any other shared sockets/descriptors such as Memcached,
  44. # and Redis. TokyoCabinet file handles are safe to reuse
  45. # between any number of forked children (assuming your kernel
  46. # correctly implements pread()/pwrite() system calls)
  47. end