lib/zbatery.rb in zbatery-0.2.1 vs lib/zbatery.rb in zbatery-0.3.0
- old
+ new
@@ -1,19 +1,20 @@
# -*- encoding: binary -*-
+# :enddoc:
require 'rainbows'
module Zbatery
# current version of Zbatery
- VERSION = "0.2.1"
+ VERSION = "0.3.0"
class << self
# runs the Zbatery HttpServer with +app+ and +options+ and does
# not return until the server has exited.
def run(app, options = {})
- HttpServer.new(app, options).start.join
+ Rainbows::HttpServer.new(app, options).start.join
end
end
Rainbows::Const::RACK_DEFAULTS["SERVER_SOFTWARE"] = "Zbatery #{VERSION}"
@@ -30,12 +31,42 @@
# we don't actually fork workers, but allow using the
# {before,after}_fork hooks found in Unicorn/Rainbows!
# config files...
FORK_HOOK = lambda { |_,_| }
- class HttpServer < Rainbows::HttpServer
+end
+# :stopdoc:
+# override stuff we don't need or can't use portably
+module Rainbows
+
+ 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
+ Rainbows::Response.setup(self.class)
+ Rainbows::MaxBody.setup
+
+ # 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
+ def G.tick
+ alive
+ end
+
+ class HttpServer
+
# this class is only used to avoid breaking Unicorn user switching
class DeadIO
def chown(*args); end
end
@@ -113,47 +144,20 @@
exit!(0) unless graceful
end
def before_fork
hook = super
- hook == FORK_HOOK or
+ hook == Zbatery::FORK_HOOK or
logger.warn "calling before_fork without forking"
hook
end
def after_fork
hook = super
- hook == FORK_HOOK or
+ hook == Zbatery::FORK_HOOK or
logger.warn "calling after_fork without having forked"
hook
end
- end
-end
-
-# :stopdoc:
-# override stuff we don't need or can't use portably
-module Rainbows
-
- 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
- def G.tick
- alive
end
end
module Unicorn