123456789_123456789_123456789_123456789_123456789_

Class: Puma::Runner

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Inherits: Object
Defined in: lib/puma/runner.rb

Overview

Generic class that is used by Cluster and Single to serve requests. This class spawns a new instance of Server via a call to #start_server.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(cli, events) ⇒ Runner

[ GitHub ]

  
# File 'lib/puma/runner.rb', line 11

def initialize(cli, events)
  @launcher = cli
  @events = events
  @options = cli.options
  @app = nil
  @control = nil
  @started_at = Time.now
end

Instance Attribute Details

#app (readonly)

[ GitHub ]

  
# File 'lib/puma/runner.rb', line 141

def app
  @app ||= @launcher.config.app
end

#development?Boolean (readonly)

[ GitHub ]

  
# File 'lib/puma/runner.rb', line 20

def development?
  @options[:environment] == "development"
end

#redirected_io?Boolean (readonly)

[ GitHub ]

  
# File 'lib/puma/runner.rb', line 94

def redirected_io?
  @options[:redirect_stdout] || @options[:redirect_stderr]
end

#ruby_engine (readonly)

[ GitHub ]

  
# File 'lib/puma/runner.rb', line 72

def ruby_engine
  if !defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby"
    "ruby #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
  else
    if defined?(RUBY_ENGINE_VERSION)
      "#{RUBY_ENGINE} #{RUBY_ENGINE_VERSION} - ruby #{RUBY_VERSION}"
    else
      "#{RUBY_ENGINE} #{RUBY_VERSION}"
    end
  end
end

#test?Boolean (readonly)

[ GitHub ]

  
# File 'lib/puma/runner.rb', line 24

def test?
  @options[:environment] == "test"
end

Instance Method Details

#close_control_listeners

Version:

  • 5.0.0

[ GitHub ]

  
# File 'lib/puma/runner.rb', line 67

def close_control_listeners
  @control.binder.close_listeners if @control
end

#debug(str)

[ GitHub ]

  
# File 'lib/puma/runner.rb', line 41

def debug(str)
  @events.log "- #{str}" if @options[:debug]
end

#error(str)

[ GitHub ]

  
# File 'lib/puma/runner.rb', line 37

def error(str)
  @events.error str
end

#load_and_bind

[ GitHub ]

  
# File 'lib/puma/runner.rb', line 124

def load_and_bind
  unless @launcher.config.app_configured?
    error "No application configured, nothing to run"
    exit 1
  end

  begin
    @app = @launcher.config.app
  rescue Exception => e
    log "! Unable to load application: #{e.class}: #{e.message}"
    raise e
  end

  @launcher.binder.parse @options[:binds], self
end

#log(str)

[ GitHub ]

  
# File 'lib/puma/runner.rb', line 28

def log(str)
  @events.log str
end

#output_header(mode)

[ GitHub ]

  
# File 'lib/puma/runner.rb', line 84

def output_header(mode)
  min_t = @options[:min_threads]
  max_t = @options[:max_threads]

  log "Puma starting in #{mode} mode..."
  log "* Version #{Puma::Const::PUMA_VERSION} (#{ruby_engine}), codename: #{Puma::Const::CODE_NAME}"
  log "* Min threads: #{min_t}, max threads: #{max_t}"
  log "* Environment: #{ENV['RACK_ENV']}"
end

#redirect_io

[ GitHub ]

  
# File 'lib/puma/runner.rb', line 98

def redirect_io
  stdout = @options[:redirect_stdout]
  stderr = @options[:redirect_stderr]
  append = @options[:redirect_append]

  if stdout
    unless Dir.exist?(File.dirname(stdout))
      raise "Cannot redirect STDOUT to #{stdout}"
    end

    STDOUT.reopen stdout, (append ? "a" : "w")
    STDOUT.sync = true
    STDOUT.puts "=== puma startup: #{Time.now} ==="
  end

  if stderr
    unless Dir.exist?(File.dirname(stderr))
      raise "Cannot redirect STDERR to #{stderr}"
    end

    STDERR.reopen stderr, (append ? "a" : "w")
    STDERR.sync = true
    STDERR.puts "=== puma startup: #{Time.now} ==="
  end
end

#start_control

[ GitHub ]

  
# File 'lib/puma/runner.rb', line 45

def start_control
  str = @options[:control_url]
  return unless str

  require 'puma/app/status'

  if token = @options[:control_auth_token]
    token = nil if token.empty? || token == 'none'
  end

  app = Puma::App::Status.new @launcher, token

  control = Puma::Server.new app, @launcher.events,
    { min_threads: 0, max_threads: 1 }

  control.binder.parse [str], self, 'Starting control server'

  control.run
  @control = control
end

#start_server

[ GitHub ]

  
# File 'lib/puma/runner.rb', line 145

def start_server
  server = Puma::Server.new app, @launcher.events, @options
  server.inherit_binder @launcher.binder
  server
end

#stop_control

Version:

  • 5.0.0

[ GitHub ]

  
# File 'lib/puma/runner.rb', line 33

def stop_control
  @control.stop(true) if @control
end