lib/zbatery.rb in zbatery-0.1.1 vs lib/zbatery.rb in zbatery-0.2.0
- old
+ new
@@ -2,11 +2,11 @@
require 'rainbows'
module Zbatery
# current version of Zbatery
- VERSION = "0.1.1"
+ VERSION = "0.2.0"
class << self
# runs the Zbatery HttpServer with +app+ and +options+ and does
# not return until the server has exited.
@@ -58,10 +58,11 @@
end while G.alive
end
# no-op
def maintain_worker_count; end
+ def init_self_pipe!; end
# can't just do a graceful exit if reopening logs fails, so we just
# continue on...
def reopen_logs
logger.info "reopening logs"
@@ -69,10 +70,14 @@
logger.info "done reopening logs"
rescue => e
logger.error "failed reopening logs #{e.message}"
end
+ def trap_deferred(sig)
+ # nothing
+ end
+
def join
begin
trap(:INT) { stop(false) } # Mongrel trapped INT for Win32...
# try these anyways regardless of platform...
@@ -89,10 +94,17 @@
trap(sig) { logger.info "SIG#{sig} is not handled by Zbatery" }
end
rescue => e # hopefully ignores errors on Win32...
logger.error "failed to setup signal handler: #{e.message}"
end
+
+ if ready_pipe
+ ready_pipe.syswrite($$.to_s)
+ ready_pipe.close rescue nil
+ self.ready_pipe = nil
+ end
+
worker = Worker.new(0, DeadIO.new)
before_fork.call(self, worker)
worker_loop(worker) # runs forever
end
@@ -123,10 +135,18 @@
module Base
# master == worker in our case
def init_worker_process(worker)
after_fork.call(self, worker)
+ worker.user(*user) if user.kind_of?(Array) && ! worker.switched
build_app! unless preload_app
+
+ # avoid spurious wakeups and blocking-accept() with 1.8 green threads
+ if RUBY_VERSION.to_f < 1.9
+ require "io/nonblock"
+ HttpServer::LISTENERS.each { |l| l.nonblock = true }
+ end
+
logger.info "Zbatery #@use worker_connections=#@worker_connections"
end
end
# we can't/don't need to do the fchmod heartbeat Unicorn/Rainbows! does