writer_thread_spawn: factor out Client.quit
[rainbows.git] / lib / rainbows / base.rb
blobbf9ef8722840c74c382fa4a9fd6edeccaf48c3cc
1 # -*- encoding: binary -*-
3 # base class for \Rainbows! concurrency models, this is currently used by
4 # ThreadSpawn and ThreadPool models.  Base is also its own
5 # (non-)concurrency model which is basically Unicorn-with-keepalive, and
6 # not intended for production use, as keepalive with a pure prefork
7 # concurrency model is extremely expensive.
8 module Rainbows::Base
10   # :stopdoc:
11   include Rainbows::ProcessClient
13   # shortcuts...
14   G = Rainbows::G
16   # this method is called by all current concurrency models
17   def init_worker_process(worker) # :nodoc:
18     super(worker)
19     Rainbows::Response.setup(self.class)
20     Rainbows::MaxBody.setup
21     Rainbows::RackInput.setup
22     G.tmp = worker.tmp
24     listeners = Rainbows::HttpServer::LISTENERS
25     Rainbows::HttpServer::IO_PURGATORY.concat(listeners)
27     # we're don't use the self-pipe mechanism in the Rainbows! worker
28     # since we don't defer reopening logs
29     Rainbows::HttpServer::SELF_PIPE.each { |x| x.close }.clear
30     trap(:USR1) { reopen_worker_logs(worker.nr) }
31     trap(:QUIT) { G.quit! }
32     [:TERM, :INT].each { |sig| trap(sig) { exit!(0) } } # instant shutdown
33     Rainbows::ProcessClient.const_set(:APP, G.server.app)
34     logger.info "Rainbows! #@use worker_connections=#@worker_connections"
35   end
37   def self.included(klass) # :nodoc:
38     klass.const_set :LISTENERS, Rainbows::HttpServer::LISTENERS
39     klass.const_set :G, Rainbows::G
40   end
42   # :startdoc:
43 end