Method: Pitchfork::HttpServer#start

Defined in:
lib/pitchfork/http_server.rb

#start(sync = true) ⇒ Object

Runs the thing. Returns self so you can run join on it



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/pitchfork/http_server.rb', line 158

def start(sync = true)
  Pitchfork.enable_child_subreaper # noop if not supported

  # This socketpair is used to wake us up from select(2) in #join when signals
  # are trapped.  See trap_deferred.
  # It's also used by newly spawned children to send their soft_signal pipe
  # to the monitor when they are spawned.
  @control_socket.replace(Pitchfork.socketpair)
  Info.keep_ios(@control_socket)
  @monitor_pid = $$

  # setup signal handlers before writing pid file in case people get
  # trigger happy and send signals as soon as the pid file exists.
  # Note that signals don't actually get handled until the #join method
  @queue_sigs.each { |sig| trap(sig) { @sig_queue << sig; awaken_monitor } }
  trap(:CHLD) { awaken_monitor }

  if REFORKING_AVAILABLE
    spawn_initial_mold
    wait_for_pending_workers
    unless @children.mold
      raise BootFailure, "The initial mold failed to boot"
    end
  else
    build_app!
    bind_listeners!
    after_mold_fork.call(self, Worker.new(nil, pid: $$).promoted!(@spawn_timeout))
  end

  if sync
    spawn_missing_workers
    # We could just return here as we'd register them later in #join.
    # However a good part of the test suite assumes #start only return
    # once all initial workers are spawned.
    wait_for_pending_workers
  end

  @after_monitor_ready&.call(self)

  self
end