lib/puma/cli.rb
def run
      parse_options

      app = @config.app

      write_pid
      write_state

      min_t = @options[:min_threads]
      max_t = @options[:max_threads]

      server = Puma::Server.new app, @events
      server.min_threads = min_t
      server.max_threads = max_t

      log "Puma #{Puma::Const::PUMA_VERSION} starting..."
      log "* Min threads: #{min_t}, max threads: #{max_t}"

      @options[:binds].each do |str|
        uri = URI.parse str
        case uri.scheme
        when "tcp"
          log "* Listening on #{str}"
          server.add_tcp_listener uri.host, uri.port
        when "unix"
          log "* Listening on #{str}"
          path = "#{uri.host}#{uri.path}"

          server.add_unix_listener path
        when "ssl"
          log "* Listening on #{str}"
          params = Rack::Utils.parse_query uri.query
          require 'openssl'

          ctx = OpenSSL::SSL::SSLContext.new
          unless params['key']
            error "Please specify the SSL key via 'key='"
          end

          ctx.key = OpenSSL::PKey::RSA.new File.read(params['key'])

          unless params['cert']
            error "Please specify the SSL cert via 'cert='"
          end

          ctx.cert = OpenSSL::X509::Certificate.new File.read(params['cert'])

          ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE

          server.add_ssl_listener uri.host, uri.port, ctx
        else
          error "Invalid URI: #{str}"
        end
      end

      @server = server

      if str = @options[:control_url]
        require 'puma/app/status'

        uri = URI.parse str

        app = Puma::App::Status.new server, self

        if token = @options[:control_auth_token]
          app.auth_token = token unless token.empty? or token == :none
        end

        status = Puma::Server.new app, @events
        status.min_threads = 0
        status.max_threads = 1

        case uri.scheme
        when "tcp"
          log "* Starting status server on #{str}"
          status.add_tcp_listener uri.host, uri.port
        when "unix"
          log "* Starting status server on #{str}"
          path = "#{uri.host}#{uri.path}"

          status.add_unix_listener path
        else
          error "Invalid status URI: #{str}"
        end

        status.run
        @status = status
      end

      log "Use Ctrl-C to stop"

      begin
        server.run.join
      rescue Interrupt
        log " - Gracefully stopping, waiting for requests to finish"
        server.stop(true)
        log " - Goodbye!"
      end

      File.unlink @temp_status_path if @temp_status_path

      if @restart
        log "* Restarting..."
        restart!
      end
    end
# Parse the options, load the rackup, start the server and wait
# for it to finish.
#
Parse the options, load the rackup, start the server and wait
for it to finish.
Parse the options load the rackup start the server and wait for it to finish .
def run
      parse_options
      app = @config.app
      write_pid
      write_state
      min_t = @options[:min_threads]
      max_t = @options[:max_threads]
      server = Puma::Server.new app, @events
      server.min_threads = min_t
      server.max_threads = max_t
      log "Puma #{Puma::Const::PUMA_VERSION} starting..."
      log "* Min threads: #{min_t}, max threads: #{max_t}"
      @options[:binds].each do |str|
        uri = URI.parse str
        case uri.scheme
        when "tcp"
          log "* Listening on #{str}"
          server.add_tcp_listener uri.host, uri.port
        when "unix"
          log "* Listening on #{str}"
          path = "#{uri.host}#{uri.path}"
          server.add_unix_listener path
        when "ssl"
          log "* Listening on #{str}"
          params = Rack::Utils.parse_query uri.query
          require 'openssl'
          ctx = OpenSSL::SSL::SSLContext.new
          unless params['key']
            error "Please specify the SSL key via 'key='"
          end
          ctx.key = OpenSSL::PKey::RSA.new File.read(params['key'])
          unless params['cert']
            error "Please specify the SSL cert via 'cert='"
          end
          ctx.cert = OpenSSL::X509::Certificate.new File.read(params['cert'])
          ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
          server.add_ssl_listener uri.host, uri.port, ctx
        else
          error "Invalid URI: #{str}"
        end
      end
      @server = server
      if str = @options[:control_url]
        require 'puma/app/status'
        uri = URI.parse str
        app = Puma::App::Status.new server, self
        if token = @options[:control_auth_token]
          app.auth_token = token unless token.empty? or token == :none
        end
        status = Puma::Server.new app, @events
        status.min_threads = 0
        status.max_threads = 1
        case uri.scheme
        when "tcp"
          log "* Starting status server on #{str}"
          status.add_tcp_listener uri.host, uri.port
        when "unix"
          log "* Starting status server on #{str}"
          path = "#{uri.host}#{uri.path}"
          status.add_unix_listener path
        else
          error "Invalid status URI: #{str}"
        end
        status.run
        @status = status
      end
      log "Use Ctrl-C to stop"
      begin
        server.run.join
      rescue Interrupt
        log " - Gracefully stopping, waiting for requests to finish"
        server.stop(true)
        log " - Goodbye!"
      end
      File.unlink @temp_status_path if @temp_status_path
      if @restart
        log "* Restarting..."
        restart!
      end
    end
def run parse_options app = @config . app write_pid write_state min_t = @options [ :min_threads ] max_t = @options [ :max_threads ] server = Puma :: Server . new app , @events server . min_threads = min_t server . max_threads = max_t log "Puma #{Puma::Const::PUMA_VERSION} starting..." log "* Min threads: #{min_t}, max threads: #{max_t}" @options [ :binds ] . each do | str | uri = URI . parse str case uri . scheme when "tcp" log "* Listening on #{str}" server . add_tcp_listener uri . host , uri . port when "unix" log "* Listening on #{str}" path = "#{uri.host}#{uri.path}" server . add_unix_listener path when "ssl" log "* Listening on #{str}" params = Rack :: Utils . parse_query uri . query require 'openssl' ctx = OpenSSL :: SSL :: SSLContext . new unless params [ 'key' ] error "Please specify the SSL key via 'key='" end ctx . key = OpenSSL :: PKey :: RSA . new File . read ( params [ 'key' ] ) unless params [ 'cert' ] error "Please specify the SSL cert via 'cert='" end ctx . cert = OpenSSL :: X509 :: Certificate . new File . read ( params [ 'cert' ] ) ctx . verify_mode = OpenSSL :: SSL :: VERIFY_NONE server . add_ssl_listener uri . host , uri . port , ctx else error "Invalid URI: #{str}" end end @server = server if str = @options [ :control_url ] require 'puma/app/status' uri = URI . parse str app = Puma :: App :: Status . new server , self if token = @options [ :control_auth_token ] app . auth_token = token unless token . empty? or token == :none end status = Puma :: Server . new app , @events status . min_threads = 0 status . max_threads = 1 case uri . scheme when "tcp" log "* Starting status server on #{str}" status . add_tcp_listener uri . host , uri . port when "unix" log "* Starting status server on #{str}" path = "#{uri.host}#{uri.path}" status . add_unix_listener path else error "Invalid status URI: #{str}" end status . run @status = status end log "Use Ctrl-C to stop" begin server . run . join rescue Interrupt log " - Gracefully stopping, waiting for requests to finish" server . stop ( true ) log " - Goodbye!" end File . unlink @temp_status_path if @temp_status_path if @restart log "* Restarting..." restart! end end
Parse the options, load the rackup, start the server and wait
for it to finish.
Parse the options load the rackup start the server and wait for it to finish .