Module: Rack::Handler::Puma

Defined in:
lib/rack/handler/puma.rb

Constant Summary

DEFAULT_OPTIONS =
{
  :Host => '0.0.0.0',
  :Port => 8080,
  :Threads => '0:16',
  :Verbose => false
}

Class Method Summary collapse

Class Method Details

.run(app, options = {}) {|server| ... } ⇒ Object

Yields:

  • (server)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rack/handler/puma.rb', line 14

def self.run(app, options = {})
  options  = DEFAULT_OPTIONS.merge(options)

  if options[:Verbose]
    app = Rack::CommonLogger.new(app, STDOUT)
  end

  if options[:environment]
    ENV['RACK_ENV'] = options[:environment].to_s
  end

  server   = ::Puma::Server.new(app)
  min, max = options[:Threads].split(':', 2)

  puts "Puma #{::Puma::Const::PUMA_VERSION} starting..."
  puts "* Min threads: #{min}, max threads: #{max}"
  puts "* Environment: #{ENV['RACK_ENV']}"
  puts "* Listening on tcp://#{options[:Host]}:#{options[:Port]}"

  server.add_tcp_listener options[:Host], options[:Port]
  server.min_threads = min
  server.max_threads = max
  yield server if block_given?

  begin
    server.run.join
  rescue Interrupt
    puts "* Gracefully stopping, waiting for requests to finish"
    server.stop(true)
    puts "* Goodbye!"
  end

end

.valid_optionsObject



48
49
50
51
52
53
54
55
# File 'lib/rack/handler/puma.rb', line 48

def self.valid_options
  {
    "Host=HOST"       => "Hostname to listen on (default: localhost)",
    "Port=PORT"       => "Port to listen on (default: 8080)",
    "Threads=MIN:MAX" => "min:max threads to use (default 0:16)",
    "Quiet"           => "Don't report each request"
  }
end