1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Move starting control server to after daemonization

This commit is contained in:
Evan Phoenix 2013-07-08 22:36:43 -07:00
parent 2425d9643e
commit c68ea5e46b
4 changed files with 50 additions and 38 deletions

View file

@ -287,7 +287,6 @@ module Puma
end
def graceful_stop
@control.stop(true) if @control
@runner.stop_blocked
log "- Goodbye!"
end
@ -428,10 +427,6 @@ module Puma
setup_signals
if cont = @options[:control_url]
start_control cont
end
@status = :run
@runner.run
@ -443,8 +438,10 @@ module Puma
graceful_stop
when :restart
log "* Restarting..."
@control.stop true if @control
@runner.before_restart
restart!
when :exit
# nothing
end
end
@ -467,44 +464,13 @@ module Puma
if jruby?
Signal.trap("INT") do
@status = :exit
graceful_stop
exit
end
end
end
def start_control(str)
require 'puma/app/status'
uri = URI.parse str
app = Puma::App::Status.new self
if token = @options[:control_auth_token]
app.auth_token = token unless token.empty? or token == :none
end
control = Puma::Server.new app, @events
control.min_threads = 0
control.max_threads = 1
case uri.scheme
when "tcp"
log "* Starting control server on #{str}"
control.add_tcp_listener uri.host, uri.port
when "unix"
log "* Starting control server on #{str}"
path = "#{uri.host}#{uri.path}"
control.add_unix_listener path
else
error "Invalid control URI: #{str}"
end
control.run
@control = control
end
def stop
@status = :stop
@runner.stop

View file

@ -175,6 +175,7 @@ module Puma
def stop_blocked
@status = :stop if @status == :run
wakeup!
@control.stop(true) if @control
Process.waitall
end
@ -258,6 +259,8 @@ module Puma
redirect_io
start_control
@cli.write_state
@master_read, @worker_write = read, @wakeup

View file

@ -4,6 +4,7 @@ module Puma
@cli = cli
@options = cli.options
@app = nil
@control = nil
end
def daemon?
@ -22,6 +23,45 @@ module Puma
@cli.error str
end
def before_restart
@control.stop(true) if @control
end
def start_control
str = @options[:control_url]
return unless str
require 'puma/app/status'
uri = URI.parse str
app = Puma::App::Status.new @cli
if token = @options[:control_auth_token]
app.auth_token = token unless token.empty? or token == :none
end
control = Puma::Server.new app, @cli.events
control.min_threads = 0
control.max_threads = 1
case uri.scheme
when "tcp"
log "* Starting control server on #{str}"
control.add_tcp_listener uri.host, uri.port
when "unix"
log "* Starting control server on #{str}"
path = "#{uri.host}#{uri.path}"
control.add_unix_listener path
else
error "Invalid control URI: #{str}"
end
control.run
@control = control
end
def output_header(mode)
min_t = @options[:min_threads]
max_t = @options[:max_threads]

View file

@ -22,6 +22,7 @@ module Puma
def stop_blocked
log "- Gracefully stopping, waiting for requests to finish"
@control.stop(true) if @control
@server.stop(true)
end
@ -68,6 +69,8 @@ module Puma
@cli.write_state
start_control
@server = server = start_server
unless @options[:daemon]