rainbows_config.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. def processor_count
  2. case RbConfig::CONFIG['host_os']
  3. when /darwin9/
  4. `hwprefs cpu_count`.to_i
  5. when /darwin/
  6. ((`which hwprefs` != '') ? `hwprefs thread_count` : `sysctl -n hw.ncpu`).to_i
  7. when /linux/
  8. `cat /proc/cpuinfo | grep processor | wc -l`.to_i
  9. when /freebsd/
  10. `sysctl -n hw.ncpu`.to_i
  11. when /mswin|mingw/
  12. require 'win32ole'
  13. wmi = WIN32OLE.connect("winmgmts://")
  14. cpu = wmi.ExecQuery("select NumberOfCores from Win32_Processor") # TODO count hyper-threaded in this
  15. cpu.to_enum.first.NumberOfCores
  16. end
  17. end
  18. Rainbows! do
  19. use :ThreadPool
  20. client_max_body_size 100*1024*1024 # 100 Megabytes
  21. worker_processes processor_count
  22. worker_connections 32
  23. timeout 600 # 10 minutes
  24. listen "unix:/var/run/neocities/neocities.sock", :backlog => 2048
  25. pid "/var/run/neocities/neocities.pid"
  26. stderr_path "/var/log/neocities/neocities.log"
  27. stdout_path "/var/log/neocities/neocities.log"
  28. preload_app true
  29. before_fork do |server, worker|
  30. old_pid = "/var/run/neocities/neocities.pid.oldbin"
  31. if File.exist?(old_pid) && server.pid != old_pid
  32. begin
  33. Process.kill("QUIT", File.read(old_pid).to_i)
  34. rescue Errno::ENOENT, Errno::ESRCH
  35. # someone else did our job for us
  36. end
  37. end
  38. end
  39. after_fork do |server, worker|
  40. DB.disconnect
  41. end
  42. end