2013-07-05 19:08:13 -04:00
|
|
|
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
|
|
|
|
|
2013-07-05 20:09:18 -04:00
|
|
|
output_header "single"
|
2013-07-05 19:08:13 -04:00
|
|
|
|
|
|
|
if jruby_daemon?
|
|
|
|
unless already_daemon
|
|
|
|
pid = nil
|
|
|
|
|
|
|
|
Signal.trap "SIGUSR2" do
|
|
|
|
log "* Started new process #{pid} as daemon..."
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
|
2013-07-05 19:53:52 -04:00
|
|
|
pid = @cli.jruby_daemon_start
|
2013-07-05 19:08:13 -04:00
|
|
|
sleep
|
|
|
|
end
|
|
|
|
else
|
|
|
|
load_and_bind
|
2013-07-06 00:13:29 -04:00
|
|
|
|
2013-07-05 20:09:18 -04:00
|
|
|
if daemon?
|
|
|
|
log "* Daemonizing..."
|
|
|
|
Process.daemon(true)
|
|
|
|
end
|
2013-07-05 19:08:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
@cli.write_state
|
|
|
|
|
2013-07-06 00:13:29 -04:00
|
|
|
@server = server = start_server
|
2013-07-05 19:08:13 -04:00
|
|
|
|
|
|
|
unless @options[:daemon]
|
|
|
|
log "Use Ctrl-C to stop"
|
|
|
|
end
|
|
|
|
|
|
|
|
redirect_io
|
|
|
|
|
2013-07-05 19:54:15 -04:00
|
|
|
@cli.events.fire_on_booted!
|
|
|
|
|
2013-07-05 19:08:13 -04:00
|
|
|
begin
|
|
|
|
server.run.join
|
|
|
|
rescue Interrupt
|
|
|
|
# Swallow it
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|