Module: Unicorn
- Defined in:
- lib/unicorn.rb,
lib/unicorn/util.rb,
lib/unicorn/const.rb,
lib/unicorn/oob_gc.rb,
lib/unicorn/tee_input.rb,
lib/unicorn/cgi_wrapper.rb,
lib/unicorn/configurator.rb,
lib/unicorn/http_request.rb,
lib/unicorn/app/old_rails.rb,
lib/unicorn/http_response.rb,
lib/unicorn/socket_helper.rb,
ext/unicorn_http/unicorn_http.c
Overview
Unicorn module containing all of the classes (include C extensions) for running a Unicorn web server. It contains a minimalist HTTP server with just enough functionality to service web application requests fast as possible.
Defined Under Namespace
Modules: App, Const, SocketHelper Classes: CGIWrapper, ClientShutdown, Configurator, HttpParser, HttpParserError, HttpRequest, HttpResponse, HttpServer, Launcher, OobGC, TeeInput, TmpIO, Util
Class Method Summary collapse
-
.builder(ru, opts) ⇒ Object
This returns a lambda to pass in as the app, this does not “build” the app (which we defer based on the outcome of “preload_app” in the Unicorn config).
-
.listener_names ⇒ Object
returns an array of strings representing TCP listen socket addresses and Unix domain socket paths.
- .run(app, options = {}) ⇒ Object
Class Method Details
.builder(ru, opts) ⇒ Object
This returns a lambda to pass in as the app, this does not “build” the app (which we defer based on the outcome of “preload_app” in the Unicorn config). The returned lambda will be called when it is time to build the app.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/unicorn.rb', line 35 def builder(ru, opts) if ru =~ /\.ru\z/ # parse embedded command-line options in config.ru comments /^#\\(.*)/ =~ File.read(ru) and opts.parse!($1.split(/\s+/)) end lambda do || inner_app = case ru when /\.ru$/ raw = File.read(ru) raw.sub!(/^__END__\n.*/, '') eval("Rack::Builder.new {(#{raw}\n)}.to_app", TOPLEVEL_BINDING, ru) else require ru Object.const_get(File.basename(ru, '.rb').capitalize) end pp({ :inner_app => inner_app }) if $DEBUG # return value, matches rackup defaults based on env case ENV["RACK_ENV"] when "development" Rack::Builder.new do use Rack::CommonLogger, $stderr use Rack::ShowExceptions use Rack::Lint run inner_app end.to_app when "deployment" Rack::Builder.new do use Rack::CommonLogger, $stderr run inner_app end.to_app else inner_app end end end |
.listener_names ⇒ Object
returns an array of strings representing TCP listen socket addresses and Unix domain socket paths. This is useful for use with Raindrops::Middleware under Linux: raindrops.bogomips.org/
77 78 79 |
# File 'lib/unicorn.rb', line 77 def listener_names HttpServer::LISTENERS.map { |io| SocketHelper.sock_name(io) } end |
.run(app, options = {}) ⇒ Object
27 28 29 |
# File 'lib/unicorn.rb', line 27 def run(app, = {}) HttpServer.new(app, ).start.join end |