Sha256: 4303a82187860132b322a7a42a5329ac1132eab9c613245d8f680e0078841f34

Contents?: true

Size: 1.68 KB

Versions: 53

Compression:

Stored size: 1.68 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 = 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

      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

# This is to trick newrelic into enabling the agent automatically.
module Mongrel
  class HttpServer
  end
end

Version data entries

53 entries across 53 versions & 4 rubygems

Version Path
rsense-server-0.5.11 vendor/gems/puma-2.8.2-java/lib/rack/handler/puma.rb
rsense-server-0.5.10 vendor/gems/puma-2.8.2-java/lib/rack/handler/puma.rb
rsense-server-0.5.9 vendor/gems/puma-2.8.2-java/lib/rack/handler/puma.rb
rsense-server-0.5.8 vendor/gems/puma-2.8.2-java/lib/rack/handler/puma.rb
rsense-server-0.5.7 vendor/gems/puma-2.8.2-java/lib/rack/handler/puma.rb
rsense-server-0.5.6 vendor/gems/puma-2.8.2-java/lib/rack/handler/puma.rb
rsense-server-0.5.5 vendor/gems/puma-2.8.2-java/lib/rack/handler/puma.rb
rsense-server-0.5.4 vendor/gems/puma-2.8.2-java/lib/rack/handler/puma.rb
rsense-server-0.5.2 vendor/gems/puma-2.8.2-java/lib/rack/handler/puma.rb
rsense-server-0.5.0 vendor/gems/puma-2.8.2-java/lib/rack/handler/puma.rb
puma-2.8.2-java lib/rack/handler/puma.rb
puma-2.8.2 lib/rack/handler/puma.rb
puma-2.8.1-java lib/rack/handler/puma.rb
puma-2.8.1 lib/rack/handler/puma.rb
puma-2.8.0-java lib/rack/handler/puma.rb
puma-2.8.0 lib/rack/handler/puma.rb
mango-0.8.0 vendor/bundler/ruby/2.1.0/gems/puma-2.7.1/lib/rack/handler/puma.rb
mango-0.7.1 vendor/bundler/ruby/2.0.0/gems/puma-2.6.0/lib/rack/handler/puma.rb
puma-2.7.1-java lib/rack/handler/puma.rb
puma-2.7.1 lib/rack/handler/puma.rb