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 end
def graceful_stop def graceful_stop
@control.stop(true) if @control
@runner.stop_blocked @runner.stop_blocked
log "- Goodbye!" log "- Goodbye!"
end end
@ -428,10 +427,6 @@ module Puma
setup_signals setup_signals
if cont = @options[:control_url]
start_control cont
end
@status = :run @status = :run
@runner.run @runner.run
@ -443,8 +438,10 @@ module Puma
graceful_stop graceful_stop
when :restart when :restart
log "* Restarting..." log "* Restarting..."
@control.stop true if @control @runner.before_restart
restart! restart!
when :exit
# nothing
end end
end end
@ -467,44 +464,13 @@ module Puma
if jruby? if jruby?
Signal.trap("INT") do Signal.trap("INT") do
@status = :exit
graceful_stop graceful_stop
exit exit
end end
end 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 def stop
@status = :stop @status = :stop
@runner.stop @runner.stop

View file

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

View file

@ -4,6 +4,7 @@ module Puma
@cli = cli @cli = cli
@options = cli.options @options = cli.options
@app = nil @app = nil
@control = nil
end end
def daemon? def daemon?
@ -22,6 +23,45 @@ module Puma
@cli.error str @cli.error str
end 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) def output_header(mode)
min_t = @options[:min_threads] min_t = @options[:min_threads]
max_t = @options[:max_threads] max_t = @options[:max_threads]

View file

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