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

58 lines
1.6 KiB
Ruby
Raw Normal View History

2011-10-04 14:23:51 -07:00
require 'rack/handler'
require 'puma'
module Rack
module Handler
module Puma
2011-11-22 15:06:51 -08:00
DEFAULT_OPTIONS = {
:Host => '0.0.0.0',
:Port => 8080,
2011-11-22 15:06:51 -08:00
:Threads => '0:16',
2015-12-03 05:08:37 +03:00
:Verbose => false,
:Silent => false
2011-11-22 15:06:51 -08:00
}
2011-10-04 14:23:51 -07:00
def self.run(app, options = {})
options = DEFAULT_OPTIONS.merge(options)
2011-11-22 15:06:51 -08:00
if options.delete(:Verbose)
2011-11-22 15:06:51 -08:00
app = Rack::CommonLogger.new(app, STDOUT)
end
if options[:environment]
ENV['RACK_ENV'] = options[:environment].to_s
end
options[:binds] ||= []
options[:binds] << "tcp://#{ options.delete(:Host) }:#{ options.delete(:Port) }"
options[:min_threads], options[:max_threads] = options.delete(:Threads).split(':', 2)
options[:app] = app
events = options.delete(:Silent) ? ::Puma::Events.strings : ::Puma::Events.stdio
2011-10-04 14:23:51 -07:00
2016-02-04 13:18:38 -06:00
launcher = ::Puma::Launcher.new(options, :events => events)
2011-10-04 14:23:51 -07: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 14:23:51 -07: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 15:06:51 -08:00
"Threads=MIN:MAX" => "min:max threads to use (default 0:16)",
2015-10-20 14:55:42 +02:00
"Verbose" => "Don't report each request (default: false)"
2011-10-04 14:23:51 -07:00
}
end
end
register :puma, Puma
end
end