2018-09-17 12:41:14 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-07-05 19:08:13 -04:00
|
|
|
require 'puma/runner'
|
2016-09-05 14:29:16 -04:00
|
|
|
require 'puma/detect'
|
|
|
|
require 'puma/plugin'
|
2013-07-05 19:08:13 -04:00
|
|
|
|
|
|
|
module Puma
|
2018-05-01 16:44:08 -04:00
|
|
|
# This class is instantiated by the `Puma::Launcher` and used
|
|
|
|
# to boot and serve a Ruby application when no puma "workers" are needed
|
|
|
|
# i.e. only using "threaded" mode. For example `$ puma -t 1:5`
|
|
|
|
#
|
|
|
|
# At the core of this class is running an instance of `Puma::Server` which
|
|
|
|
# gets created via the `start_server` method from the `Puma::Runner` class
|
|
|
|
# that this inherits from.
|
2013-07-05 19:08:13 -04:00
|
|
|
class Single < Runner
|
|
|
|
def stats
|
2019-12-17 00:38:48 -05:00
|
|
|
{
|
2020-04-14 00:06:30 -04:00
|
|
|
started_at: @started_at.utc.iso8601
|
|
|
|
}.merge(@server.stats)
|
2013-07-05 19:08:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def restart
|
|
|
|
@server.begin_restart
|
|
|
|
end
|
|
|
|
|
|
|
|
def stop
|
2018-09-24 00:16:33 -04:00
|
|
|
@server.stop(false) if @server
|
2013-07-05 19:08:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def halt
|
|
|
|
@server.halt
|
|
|
|
end
|
|
|
|
|
|
|
|
def stop_blocked
|
|
|
|
log "- Gracefully stopping, waiting for requests to finish"
|
2013-07-09 01:36:43 -04:00
|
|
|
@control.stop(true) if @control
|
2018-09-24 00:16:33 -04:00
|
|
|
@server.stop(true) if @server
|
2013-07-05 19:08:13 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
2013-07-05 20:09:18 -04:00
|
|
|
output_header "single"
|
2013-07-05 19:08:13 -04:00
|
|
|
|
2020-03-10 14:08:34 -04:00
|
|
|
load_and_bind
|
2013-07-05 19:08:13 -04:00
|
|
|
|
2016-07-24 19:00:57 -04:00
|
|
|
Plugins.fire_background
|
|
|
|
|
2016-02-06 22:00:29 -05:00
|
|
|
@launcher.write_state
|
2013-07-05 19:08:13 -04:00
|
|
|
|
2013-07-09 01:36:43 -04:00
|
|
|
start_control
|
|
|
|
|
2013-07-06 00:13:29 -04:00
|
|
|
@server = server = start_server
|
2013-07-05 19:08:13 -04:00
|
|
|
|
2020-03-10 14:08:34 -04:00
|
|
|
|
|
|
|
log "Use Ctrl-C to stop"
|
|
|
|
redirect_io
|
2013-07-05 19:08:13 -04:00
|
|
|
|
2016-02-06 22:00:29 -05:00
|
|
|
@launcher.events.fire_on_booted!
|
2013-07-05 19:54:15 -04:00
|
|
|
|
2013-07-05 19:08:13 -04:00
|
|
|
begin
|
|
|
|
server.run.join
|
|
|
|
rescue Interrupt
|
|
|
|
# Swallow it
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|