1 # -*- encoding: binary -*-
5 class HttpServer < ::Unicorn::HttpServer
10 G.server.instance_eval(&block)
14 def initialize(app, options)
16 @logger = Unicorn::Configurator::DEFAULTS[:logger]
17 rv = super(app, options)
18 defined?(@use) or use(:Base)
19 @worker_connections ||= MODEL_WORKER_CONNECTIONS[@use]
22 def reopen_worker_logs(worker_nr)
23 logger.info "worker=#{worker_nr} reopening logs..."
24 Unicorn::Util.reopen_logs
25 logger.info "worker=#{worker_nr} done reopening logs"
27 G.quit! # let the master reopen and refork us
32 # Add one second to the timeout since our fchmod heartbeat is less
33 # precise (and must be more conservative) than Unicorn does. We
34 # handle many clients per process and can't chmod on every
35 # connection we accept without wasting cycles. That added to the
36 # fact that we let clients keep idle connections open for long
37 # periods of time means we have to chmod at a fixed interval.
44 model = args.shift or return @use
46 Rainbows.const_get(model)
48 logger.error "error loading #{model.inspect}: #{e}"
49 e.backtrace.each { |l| logger.error l }
50 raise ArgumentError, "concurrency model #{model.inspect} not supported"
54 raise ArgumentError, "concurrency model #{model.inspect} not supported"
58 when Hash; O.update(opt)
59 when Symbol; O[opt] = true
60 else; raise ArgumentError, "can't handle option: #{opt.inspect}"
63 mod.setup if mod.respond_to?(:setup)
64 Const::RACK_DEFAULTS['rainbows.model'] = @use = model.to_sym
65 Const::RACK_DEFAULTS['rack.multithread'] = !!(model.to_s =~ /Thread/)
68 when :Rev, :EventMachine, :NeverBlock
69 Const::RACK_DEFAULTS['rainbows.autochunk'] = true
73 def worker_connections(*args)
74 return @worker_connections if args.empty?
76 (Integer === nr && nr > 0) or
77 raise ArgumentError, "worker_connections must be a positive Integer"
78 @worker_connections = nr
81 def keepalive_timeout(nr)
82 (Integer === nr && nr >= 0) or
83 raise ArgumentError, "keepalive must be a non-negative Integer"
87 def client_max_body_size(nr)
88 err = "client_max_body_size must be nil or a non-negative Integer"
92 nr >= 0 or raise ArgumentError, err
94 raise ArgumentError, err
96 Rainbows.max_bytes = nr