mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
93 lines
1.7 KiB
Ruby
93 lines
1.7 KiB
Ruby
require 'puma/runner'
|
|
|
|
module Puma
|
|
class Single < Runner
|
|
def stats
|
|
b = @server.backlog
|
|
r = @server.running
|
|
%Q!{ "backlog": #{b}, "running": #{r} }!
|
|
end
|
|
|
|
def restart
|
|
@server.begin_restart
|
|
end
|
|
|
|
def stop
|
|
@server.stop false
|
|
end
|
|
|
|
def halt
|
|
@server.halt
|
|
end
|
|
|
|
def stop_blocked
|
|
log "- Gracefully stopping, waiting for requests to finish"
|
|
@server.stop(true)
|
|
end
|
|
|
|
def jruby_daemon?
|
|
daemon? and @cli.jruby?
|
|
end
|
|
|
|
def run
|
|
already_daemon = false
|
|
|
|
if jruby_daemon?
|
|
require 'puma/jruby_restart'
|
|
|
|
if JRubyRestart.daemon?
|
|
# load and bind before redirecting IO so errors show up on stdout/stderr
|
|
load_and_bind
|
|
end
|
|
|
|
already_daemon = JRubyRestart.daemon_init
|
|
end
|
|
|
|
output_header
|
|
|
|
if jruby_daemon?
|
|
unless already_daemon
|
|
require 'puma/jruby_restart'
|
|
|
|
pid = nil
|
|
|
|
Signal.trap "SIGUSR2" do
|
|
log "* Started new process #{pid} as daemon..."
|
|
exit
|
|
end
|
|
|
|
pid = JRubyRestart.daemon_start(@restart_dir, restart_args)
|
|
sleep
|
|
end
|
|
else
|
|
load_and_bind
|
|
Process.daemon(true) if daemon?
|
|
end
|
|
|
|
@cli.write_state
|
|
|
|
server = Puma::Server.new @app, @cli.events
|
|
server.binder = @cli.binder
|
|
server.min_threads = @options[:min_threads]
|
|
server.max_threads = @options[:max_threads]
|
|
|
|
unless development?
|
|
server.leak_stack_on_error = false
|
|
end
|
|
|
|
@server = server
|
|
|
|
unless @options[:daemon]
|
|
log "Use Ctrl-C to stop"
|
|
end
|
|
|
|
redirect_io
|
|
|
|
begin
|
|
server.run.join
|
|
rescue Interrupt
|
|
# Swallow it
|
|
end
|
|
end
|
|
end
|
|
end
|