Sha256: 3a900bdb8db874c217033da105c6598ae606607e48e9e8a11538529216d3883a

Contents?: true

Size: 1.55 KB

Versions: 11

Compression:

Stored size: 1.55 KB

Contents

module Padrino

  def self.run!(*args)
    Padrino.load! unless Padrino.loaded?
    Server.build(*args)
  end

  module Server

    class LoadError < RuntimeError; end

    Handlers = %w[thin mongrel webrick] unless const_defined?(:Handlers)

    private
      def self.build(host="localhost", port=3000, adapter=nil)
        handler_name = adapter ? adapter.to_s.capitalize : detect_handler.name.gsub(/.*::/, '')

        begin
          handler = Rack::Handler.get(handler_name.downcase)
        rescue
          raise LoadError, "#{handler_name} not supported yet, available adapters are: #{Handlers.inspect}"
          exit
        end

        handler.run Padrino.application, :Host => host, :Port => port do |server|
          trap(:INT) do
            # Use thins' hard #stop! if available, otherwise just #stop
            server.respond_to?(:stop!) ? server.stop! : server.stop
            puts "<= Padrino has ended his set (crowd applauds)"
          end
        end
      rescue RuntimeError => e
        if e.message =~ /no acceptor/
          puts "=> Someone is already performing on port #{port}!"
        else
          raise e
        end
      rescue Errno::EADDRINUSE
        puts "=> Someone is already performing on port #{port}!"
      end

      def self.detect_handler
        Handlers.each do |server_name|
          begin
            return Rack::Handler.get(server_name.downcase)
          rescue LoadError
          rescue NameError
          end
        end
        raise LoadError, "Server handler (#{servers.join(',')}) not found."
      end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
padrino-core-0.6.3 lib/padrino-core/server.rb
padrino-core-0.6.2 lib/padrino-core/server.rb
padrino-core-0.6.1 lib/padrino-core/server.rb
padrino-core-0.5.0 lib/padrino-core/server.rb
padrino-core-0.4.6 lib/padrino-core/server.rb
padrino-core-0.4.5 lib/padrino-core/server.rb
padrino-core-0.2.9 lib/padrino-core/server.rb
padrino-core-0.2.6 lib/padrino-core/server.rb
padrino-core-0.2.5 lib/padrino-core/server.rb
padrino-core-0.2.2 lib/padrino-core/server.rb
padrino-core-0.2.1 lib/padrino-core/server.rb