From 03b7904f597d80ed7c8e5ae19e2af8d0e0c581ba Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 11 Oct 2009 01:51:27 -0700 Subject: expand and share init_worker_process This can be common across everything --- lib/rainbows/base.rb | 13 +++++++++++++ lib/rainbows/revactor.rb | 4 ---- lib/rainbows/thread_pool.rb | 6 ------ lib/rainbows/thread_spawn.rb | 6 ------ 4 files changed, 13 insertions(+), 16 deletions(-) (limited to 'lib/rainbows') diff --git a/lib/rainbows/base.rb b/lib/rainbows/base.rb index da3fff0..2da6d41 100644 --- a/lib/rainbows/base.rb +++ b/lib/rainbows/base.rb @@ -22,6 +22,19 @@ module Rainbows logger.error e.backtrace.join("\n") end + def init_worker_process(worker) + super(worker) + + # we're don't use the self-pipe mechanism in the Rainbows! worker + # since we don't defer reopening logs + HttpServer::SELF_PIPE.each { |x| x.close }.clear + trap(:USR1) { reopen_worker_logs(worker.nr) rescue nil } + # closing anything we IO.select on will raise EBADF + trap(:QUIT) { HttpServer::LISTENERS.map! { |s| s.close rescue nil } } + [:TERM, :INT].each { |sig| trap(sig) { exit(0) } } # instant shutdown + logger.info "Rainbows! #@use worker_connections=#@worker_connections" + end + # once a client is accepted, it is processed in its entirety here # in 3 easy steps: read request, call app, write app response def process_client(client) diff --git a/lib/rainbows/revactor.rb b/lib/rainbows/revactor.rb index 95cf8fe..006a3b1 100644 --- a/lib/rainbows/revactor.rb +++ b/lib/rainbows/revactor.rb @@ -78,10 +78,6 @@ module Rainbows init_worker_process(worker) alive = worker.tmp # tmp is our lifeline to the master process - trap(:USR1) { reopen_worker_logs(worker.nr) } - trap(:QUIT) { alive = false; LISTENERS.each { |s| s.close rescue nil } } - [:TERM, :INT].each { |sig| trap(sig) { exit!(0) } } # instant shutdown - root = Actor.current root.trap_exit = true diff --git a/lib/rainbows/thread_pool.rb b/lib/rainbows/thread_pool.rb index 766742e..033452c 100644 --- a/lib/rainbows/thread_pool.rb +++ b/lib/rainbows/thread_pool.rb @@ -24,12 +24,6 @@ module Rainbows alive = worker.tmp m = 0 - # closing anything we IO.select on will raise EBADF - trap(:USR1) { reopen_worker_logs(worker.nr) rescue nil } - trap(:QUIT) { LISTENERS.map! { |s| s.close rescue nil } } - [:TERM, :INT].each { |sig| trap(sig) { exit(0) } } # instant shutdown - logger.info "worker=#{worker.nr} ready with ThreadPool" - while LISTENERS.first && master_pid == Process.ppid maintain_thread_count(threads) threads.list.each do |thr| diff --git a/lib/rainbows/thread_spawn.rb b/lib/rainbows/thread_spawn.rb index 32040ad..ef5d3db 100644 --- a/lib/rainbows/thread_spawn.rb +++ b/lib/rainbows/thread_spawn.rb @@ -20,12 +20,6 @@ module Rainbows m = 0 limit = worker_connections - # closing anything we IO.select on will raise EBADF - trap(:USR1) { reopen_worker_logs(worker.nr) rescue nil } - trap(:QUIT) { LISTENERS.map! { |s| s.close rescue nil } } - [:TERM, :INT].each { |sig| trap(sig) { exit(0) } } # instant shutdown - logger.info "worker=#{worker.nr} ready with ThreadSpawn" - begin ret = begin alive.chmod(m = 0 == m ? 1 : 0) -- cgit v1.2.3-24-ge0c7