Class: Puma::Single

Inherits:
Runner show all
Defined in:
lib/puma/single.rb

Overview

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.

Constant Summary

Constants included from Const::PipeRequest

Const::PipeRequest::PIPE_BOOT, Const::PipeRequest::PIPE_EXTERNAL_TERM, Const::PipeRequest::PIPE_FORK, Const::PipeRequest::PIPE_IDLE, Const::PipeRequest::PIPE_PING, Const::PipeRequest::PIPE_TERM, Const::PipeRequest::PIPE_WAKEUP

Instance Attribute Summary collapse

Attributes inherited from Runner

#app, #options

Instance Method Summary collapse

Methods inherited from Runner

#close_control_listeners, #debug, #development?, #error, #initialize, #load_and_bind, #log, #output_header, #redirect_io, #redirected_io?, #start_control, #start_server, #stop_control, #test?, #wakeup!, #warn_ruby_mn_threads

Constructor Details

This class inherits a constructor from Puma::Runner

Instance Attribute Details

#statsObject (readonly)



17
18
19
20
21
# File 'lib/puma/single.rb', line 17

def stats
  {
    started_at: utc_iso8601(@started_at)
  }.merge(@server&.stats || {}).merge(super)
end

Instance Method Details

#haltObject



31
32
33
# File 'lib/puma/single.rb', line 31

def halt
  @server&.halt
end

#restartObject



23
24
25
# File 'lib/puma/single.rb', line 23

def restart
  @server&.begin_restart
end

#runObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/puma/single.rb', line 41

def run
  output_header "single"

  load_and_bind

  Plugins.fire_background

  @launcher.write_state

  start_control

  @server = server = start_server
  server_thread = server.run

  log "Use Ctrl-C to stop"

  warn_ruby_mn_threads

  redirect_io

  @events.fire_after_booted!

  debug_loaded_extensions("Loaded Extensions:") if @log_writer.debug?

  begin
    server_thread.join
  rescue Interrupt
    # Swallow it
  end
end

#stopObject



27
28
29
# File 'lib/puma/single.rb', line 27

def stop
  @server&.stop false
end

#stop_blockedObject



35
36
37
38
39
# File 'lib/puma/single.rb', line 35

def stop_blocked
  log "- Gracefully stopping, waiting for requests to finish"
  @control&.stop true
  @server&.stop true
end