neocities/rainbows_config.rb

51 lines
1.3 KiB
Ruby
Raw Permalink Normal View History

2014-12-03 09:04:12 -08:00
def processor_count
case RbConfig::CONFIG['host_os']
when /darwin9/
`hwprefs cpu_count`.to_i
when /darwin/
((`which hwprefs` != '') ? `hwprefs thread_count` : `sysctl -n hw.ncpu`).to_i
when /linux/
`cat /proc/cpuinfo | grep processor | wc -l`.to_i
when /freebsd/
`sysctl -n hw.ncpu`.to_i
when /mswin|mingw/
require 'win32ole'
wmi = WIN32OLE.connect("winmgmts://")
cpu = wmi.ExecQuery("select NumberOfCores from Win32_Processor") # TODO count hyper-threaded in this
cpu.to_enum.first.NumberOfCores
end
end
2013-06-02 23:16:38 -07:00
Rainbows! do
use :ThreadPool
2013-07-07 23:13:54 +02:00
client_max_body_size 100*1024*1024 # 100 Megabytes
2013-06-02 23:16:38 -07:00
2014-12-03 09:04:12 -08:00
worker_processes processor_count
2013-06-02 23:16:38 -07:00
worker_connections 32
timeout 600 # 10 minutes
2013-06-02 23:16:38 -07:00
2013-07-07 23:13:54 +02:00
listen "unix:/var/run/neocities/neocities.sock", :backlog => 2048
2013-06-02 23:16:38 -07:00
2013-07-07 23:13:54 +02:00
pid "/var/run/neocities/neocities.pid"
stderr_path "/var/log/neocities/neocities.log"
stdout_path "/var/log/neocities/neocities.log"
2013-06-02 23:16:38 -07:00
preload_app true
2013-06-02 23:16:38 -07:00
before_fork do |server, worker|
2013-07-07 23:13:54 +02:00
old_pid = "/var/run/neocities/neocities.pid.oldbin"
2022-08-10 14:31:36 -05:00
if File.exist?(old_pid) && server.pid != old_pid
2013-06-02 23:16:38 -07:00
begin
Process.kill("QUIT", File.read(old_pid).to_i)
rescue Errno::ENOENT, Errno::ESRCH
# someone else did our job for us
end
end
end
after_fork do |server, worker|
DB.disconnect
end
2013-06-03 00:10:54 -07:00
end