Advertisement
tblanko

Untitled

Mar 30th, 2013
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 4.36 KB | None | 0 0
  1. # Sample verbose configuration file for Unicorn (not Rack)
  2. #
  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.
  7. #
  8. # See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete
  9. # documentation.
  10.  
  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 1
  14.  
  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"
  21.  
  22. APP_PATH = "/var/www"
  23.  
  24. # Help ensure your application will always spawn in the symlinked
  25. # "current" directory that Capistrano sets up.
  26. working_directory APP_PATH # available in 0.94.0+
  27.  
  28. # listen on both a Unix domain socket and a TCP port,
  29. # we use a shorter backlog for quicker failover when busy
  30. listen "/tmp/.sock", :backlog => 64
  31. listen 8080, :tcp_nopush => true
  32.  
  33. # nuke workers after 30 seconds instead of 60 seconds (the default)
  34. timeout 30
  35.  
  36. # feel free to point this anywhere accessible on the filesystem
  37. pid APP_PATH + "/tmp/pids/unicorn.pid"
  38.  
  39. # By default, the Unicorn logger will write to stderr.
  40. # Additionally, ome applications/frameworks log to stderr or stdout,
  41. # so prevent them from going to /dev/null when daemonized here:
  42. stderr_path APP_PATH + "/log/unicorn.stderr.log"
  43. stdout_path APP_PATH + "/log/unicorn.stdout.log"
  44.  
  45. # combine Ruby 2.0.0dev or REE with "preload_app true" for memory savings
  46. # http://rubyenterpriseedition.com/faq.html#adapt_apps_for_cow
  47. preload_app true
  48. GC.respond_to?(:copy_on_write_friendly=) and
  49.   GC.copy_on_write_friendly = true
  50.  
  51. # Enable this flag to have unicorn test client connections by writing the
  52. # beginning of the HTTP headers before calling the application.  This
  53. # prevents calling the application for connections that have disconnected
  54. # while queued.  This is only guaranteed to detect clients on the same
  55. # host unicorn runs on, and unlikely to detect disconnects even on a
  56. # fast LAN.
  57. check_client_connection false
  58.  
  59. before_fork do |server, worker|
  60.   # the following is highly recomended for Rails + "preload_app true"
  61.   # as there's no need for the master process to hold a connection
  62.   defined?(ActiveRecord::Base) and
  63.     ActiveRecord::Base.connection.disconnect!
  64.  
  65.   # The following is only recommended for memory/DB-constrained
  66.   # installations.  It is not needed if your system can house
  67.   # twice as many worker_processes as you have configured.
  68.   #
  69.   # # This allows a new master process to incrementally
  70.   # # phase out the old master process with SIGTTOU to avoid a
  71.   # # thundering herd (especially in the "preload_app false" case)
  72.   # # when doing a transparent upgrade.  The last worker spawned
  73.   # # will then kill off the old master process with a SIGQUIT.
  74.   # old_pid = "#{server.config[:pid]}.oldbin"
  75.   # if old_pid != server.pid
  76.   #   begin
  77.   #     sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
  78.   #     Process.kill(sig, File.read(old_pid).to_i)
  79.   #   rescue Errno::ENOENT, Errno::ESRCH
  80.   #   end
  81.   # end
  82.   #
  83.   # Throttle the master from forking too quickly by sleeping.  Due
  84.   # to the implementation of standard Unix signal handlers, this
  85.   # helps (but does not completely) prevent identical, repeated signals
  86.   # from being lost when the receiving process is busy.
  87.   # sleep 1
  88. end
  89.  
  90. after_fork do |server, worker|
  91.   # per-process listener ports for debugging/admin/migrations
  92.   # addr = "127.0.0.1:#{9293 + worker.nr}"
  93.   # server.listen(addr, :tries => -1, :delay => 5, :tcp_nopush => true)
  94.  
  95.   # the following is *required* for Rails + "preload_app true",
  96.   defined?(ActiveRecord::Base) and
  97.     ActiveRecord::Base.establish_connection
  98.  
  99.   # if preload_app is true, then you may also want to check and
  100.   # restart any other shared sockets/descriptors such as Memcached,
  101.   # and Redis.  TokyoCabinet file handles are safe to reuse
  102.   # between any number of forked children (assuming your kernel
  103.   # correctly implements pread()/pwrite() system calls)
  104. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement