Sha256: 0bd90f2751fb197c108e9aef6d0a5baa09251d4bc8e2351a8a37a5fe1e5107df

Contents?: true

Size: 1.59 KB

Versions: 13

Compression:

Stored size: 1.59 KB

Contents

require 'rack/handler'
require 'puma'

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

      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 = Integer(min)
        server.max_threads = Integer(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

      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
    end

    register :puma, Puma
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/puma-1.6.3/lib/rack/handler/puma.rb
puma-2.0.0.b1-java lib/rack/handler/puma.rb
puma-2.0.0.b1 lib/rack/handler/puma.rb
puma-1.6.3-java lib/rack/handler/puma.rb
puma-1.6.3 lib/rack/handler/puma.rb
puma-1.6.2-java lib/rack/handler/puma.rb
puma-1.6.2 lib/rack/handler/puma.rb
puma-1.6.1-java lib/rack/handler/puma.rb
puma-1.6.1 lib/rack/handler/puma.rb
puma-1.6.0-java lib/rack/handler/puma.rb
puma-1.6.0 lib/rack/handler/puma.rb
puma-1.5.0-java lib/rack/handler/puma.rb
puma-1.5.0 lib/rack/handler/puma.rb