Method: Unicorn::HttpServer#initialize

Defined in:
lib/unicorn/http_server.rb

#initialize(app, options = {}) ⇒ HttpServer

Creates a working server on host:port (strange things happen if port isn’t a Number). Use HttpServer::run to start the server and HttpServer.run.join to join the thread that’s processing incoming requests on the socket.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/unicorn/http_server.rb', line 71

def initialize(app, options = {})
  @app = app
  @request = Unicorn::HttpRequest.new
  self.reexec_pid = 0
  options = options.dup
  @ready_pipe = options.delete(:ready_pipe)
  @init_listeners = options[:listeners] ? options[:listeners].dup : []
  options[:use_defaults] = true
  self.config = Unicorn::Configurator.new(options)
  self.listener_opts = {}

  # We use @self_pipe differently in the master and worker processes:
  #
  # * The master process never closes or reinitializes this once
  # initialized.  Signal handlers in the master process will write to
  # it to wake up the master from IO.select in exactly the same manner
  # djb describes in http://cr.yp.to/docs/selfpipe.html
  #
  # * The workers immediately close the pipe they inherit.  See the
  # Unicorn::Worker class for the pipe workers use.
  @self_pipe = []
  @workers = {} # hash maps PIDs to Workers
  @sig_queue = [] # signal queue used for self-piping

  # we try inheriting listeners first, so we bind them later.
  # we don't write the pid file until we've bound listeners in case
  # unicorn was started twice by mistake.  Even though our #pid= method
  # checks for stale/existing pid files, race conditions are still
  # possible (and difficult/non-portable to avoid) and can be likely
  # to clobber the pid if the second start was in quick succession
  # after the first, so we rely on the listener binding to fail in
  # that case.  Some tests (in and outside of this source tree) and
  # monitoring tools may also rely on pid files existing before we
  # attempt to connect to the listener(s)
  config.commit!(self, :skip => [:listeners, :pid])
  self.orig_app = app
end