1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00
puma--puma/lib/rack/handler/puma.rb

65 lines
1.6 KiB
Ruby
Raw Normal View History

2011-10-04 17:23:51 -04:00
require 'rack/handler'
require 'puma'
module Rack
module Handler
module Puma
2011-11-22 18:06:51 -05:00
DEFAULT_OPTIONS = {
2015-12-02 21:08:37 -05:00
:Verbose => false,
:Silent => false
2011-11-22 18:06:51 -05:00
}
2011-10-04 17:23:51 -04:00
def self.run(app, options = {})
options = DEFAULT_OPTIONS.merge(options)
2011-11-22 18:06:51 -05:00
conf = ::Puma::Configuration.new do |c|
if options.delete(:Verbose)
app = Rack::CommonLogger.new(app, STDOUT)
end
2011-11-22 18:06:51 -05:00
if options[:environment]
c.environment options[:environment]
end
if options[:Threads]
min, max = options.delete(:Threads).split(':', 2)
c.threads min, max
end
host = options[:Host] || ::Puma::Configuration::DefaultTCPHost
port = options[:Port] || ::Puma::Configuration::DefaultTCPPort
c.port port, host
c.app app
end
2011-10-04 17:23:51 -04:00
events = options.delete(:Silent) ? ::Puma::Events.strings : ::Puma::Events.stdio
launcher = ::Puma::Launcher.new(conf, :events => events)
2011-10-04 17:23:51 -04:00
yield launcher if block_given?
begin
launcher.run
rescue Interrupt
puts "* Gracefully stopping, waiting for requests to finish"
launcher.stop
puts "* Goodbye!"
end
2011-10-04 17:23:51 -04:00
end
def self.valid_options
{
"Host=HOST" => "Hostname to listen on (default: localhost)",
"Port=PORT" => "Port to listen on (default: 8080)",
2011-11-22 18:06:51 -05:00
"Threads=MIN:MAX" => "min:max threads to use (default 0:16)",
2015-10-20 08:55:42 -04:00
"Verbose" => "Don't report each request (default: false)"
2011-10-04 17:23:51 -04:00
}
end
end
register :puma, Puma
end
end