Sha256: 1f217c9df9ca4f74c249eeb34686d0eb4ff403d6e83d1cfd1f8f9aebd610cb1d

Contents?: true

Size: 1.77 KB

Versions: 60

Compression:

Stored size: 1.77 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,
        :Silent => 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

        events_hander = options[:Silent] ? ::Puma::Events.strings : ::Puma::Events.stdio
        server   = ::Puma::Server.new(app, events_hander)
        min, max = options[:Threads].split(':', 2)

        log = events_hander.stdout

        log.puts "Puma #{::Puma::Const::PUMA_VERSION} starting..."
        log.puts "* Min threads: #{min}, max threads: #{max}"
        log.puts "* Environment: #{ENV['RACK_ENV']}"
        log.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
          log.puts "* Gracefully stopping, waiting for requests to finish"
          server.stop(true)
          log.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)",
          "Verbose"         => "Don't report each request (default: false)"
        }
      end
    end

    register :puma, Puma
  end
end

Version data entries

60 entries across 57 versions & 14 rubygems

Version Path
logstash-output-scalyr-0.2.1.beta vendor/bundle/jruby/2.5.0/gems/puma-2.16.0-java/lib/rack/handler/puma.rb
logstash-output-scalyr-0.2.0 vendor/bundle/jruby/2.5.0/gems/puma-2.16.0-java/lib/rack/handler/puma.rb
logstash-output-scalyr-0.2.0.beta vendor/bundle/jruby/2.5.0/gems/puma-2.16.0-java/lib/rack/handler/puma.rb
logstash-output-scalyr-0.1.26.beta vendor/bundle/jruby/2.5.0/gems/puma-2.16.0-java/lib/rack/handler/puma.rb
logstash-output-scalyr-0.1.25.beta vendor/bundle/jruby/2.5.0/gems/puma-2.16.0-java/lib/rack/handler/puma.rb
logstash-output-scalyr-0.1.24.beta vendor/bundle/jruby/2.5.0/gems/puma-2.16.0-java/lib/rack/handler/puma.rb
logstash-output-scalyr-0.1.23.beta vendor/bundle/jruby/2.5.0/gems/puma-2.16.0-java/lib/rack/handler/puma.rb
logstash-output-scalyr-0.1.22.beta vendor/bundle/jruby/2.5.0/gems/puma-2.16.0-java/lib/rack/handler/puma.rb
logstash-output-scalyr-0.1.21.beta vendor/bundle/jruby/2.5.0/gems/puma-2.16.0-java/lib/rack/handler/puma.rb
logstash-output-scalyr-0.1.20.beta vendor/bundle/jruby/2.5.0/gems/puma-2.16.0-java/lib/rack/handler/puma.rb
logstash-output-scalyr-0.1.19.beta vendor/bundle/jruby/2.5.0/gems/puma-2.16.0-java/lib/rack/handler/puma.rb
logstash-output-scalyr-0.1.18.beta vendor/bundle/jruby/2.5.0/gems/puma-2.16.0-java/lib/rack/handler/puma.rb
logstash-output-scalyr-0.1.17.beta vendor/bundle/jruby/2.5.0/gems/puma-2.16.0-java/lib/rack/handler/puma.rb
logstash-output-scalyr-0.1.16.beta vendor/bundle/jruby/2.5.0/gems/puma-2.16.0-java/lib/rack/handler/puma.rb
logstash-output-scalyr-0.1.15.beta vendor/bundle/jruby/2.5.0/gems/puma-2.16.0-java/lib/rack/handler/puma.rb
logstash-output-scalyr-0.1.14.beta vendor/bundle/jruby/2.5.0/gems/puma-2.16.0-java/lib/rack/handler/puma.rb
logstash-output-scalyr-0.1.13 vendor/bundle/jruby/2.5.0/gems/puma-2.16.0-java/lib/rack/handler/puma.rb
logstash-output-scalyr-0.1.12 vendor/bundle/jruby/2.5.0/gems/puma-2.16.0-java/lib/rack/handler/puma.rb
logstash-output-scalyr-0.1.11.beta vendor/bundle/jruby/2.5.0/gems/puma-2.16.0-java/lib/rack/handler/puma.rb
logstash-output-scalyr-0.1.10.beta vendor/bundle/jruby/2.5.0/gems/puma-2.16.0-java/lib/rack/handler/puma.rb