Class: Puma::Runner
- Inherits:
-
Object
- Object
- Puma::Runner
- Defined in:
- lib/puma/runner.rb
Instance Method Summary collapse
- #app ⇒ Object
- #before_restart ⇒ Object
- #daemon? ⇒ Boolean
- #debug(str) ⇒ Object
- #development? ⇒ Boolean
- #error(str) ⇒ Object
-
#initialize(cli, events) ⇒ Runner
constructor
A new instance of Runner.
- #load_and_bind ⇒ Object
- #log(str) ⇒ Object
- #output_header(mode) ⇒ Object
- #redirect_io ⇒ Object
- #redirected_io? ⇒ Boolean
- #ruby_engine ⇒ Object
- #start_control ⇒ Object
- #start_server ⇒ Object
Constructor Details
#initialize(cli, events) ⇒ Runner
Returns a new instance of Runner.
6 7 8 9 10 11 12 |
# File 'lib/puma/runner.rb', line 6 def initialize(cli, events) @launcher = cli @events = events @options = cli. @app = nil @control = nil end |
Instance Method Details
#app ⇒ Object
147 148 149 |
# File 'lib/puma/runner.rb', line 147 def app @app ||= @launcher.config.app end |
#before_restart ⇒ Object
26 27 28 |
# File 'lib/puma/runner.rb', line 26 def before_restart @control.stop(true) if @control end |
#daemon? ⇒ Boolean
14 15 16 |
# File 'lib/puma/runner.rb', line 14 def daemon? @options[:daemon] end |
#debug(str) ⇒ Object
34 35 36 |
# File 'lib/puma/runner.rb', line 34 def debug(str) @events.log "- #{str}" if @options[:debug] end |
#development? ⇒ Boolean
18 19 20 |
# File 'lib/puma/runner.rb', line 18 def development? @options[:environment] == "development" end |
#error(str) ⇒ Object
30 31 32 |
# File 'lib/puma/runner.rb', line 30 def error(str) @events.error str end |
#load_and_bind ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/puma/runner.rb', line 130 def load_and_bind unless @launcher.config.app_configured? error "No application configured, nothing to run" exit 1 end # Load the app before we daemonize. begin @app = @launcher.config.app rescue Exception => e log "! Unable to load application: #{e.class}: #{e.}" raise e end @launcher.binder.parse @options[:binds], self end |
#log(str) ⇒ Object
22 23 24 |
# File 'lib/puma/runner.rb', line 22 def log(str) @events.log str end |
#output_header(mode) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/puma/runner.rb', line 86 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']}" if @options[:mode] == :tcp log "* Mode: Lopez Express (tcp)" end end |
#redirect_io ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/puma/runner.rb', line 104 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 |
#redirected_io? ⇒ Boolean
100 101 102 |
# File 'lib/puma/runner.rb', line 100 def redirected_io? @options[:redirect_stdout] || @options[:redirect_stderr] end |
#ruby_engine ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/puma/runner.rb', line 74 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 |
#start_control ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/puma/runner.rb', line 38 def start_control str = @options[:control_url] return unless str require 'puma/app/status' uri = URI.parse str app = Puma::App::Status.new @launcher if token = @options[:control_auth_token] app.auth_token = token unless token.empty? or token == :none end control = Puma::Server.new app, @launcher.events control.min_threads = 0 control.max_threads = 1 case uri.scheme when "tcp" log "* Starting control server on #{str}" control.add_tcp_listener uri.host, uri.port when "unix" log "* Starting control server on #{str}" path = "#{uri.host}#{uri.path}" mask = @options[:control_url_umask] control.add_unix_listener path, mask else error "Invalid control URI: #{str}" end control.run @control = control end |
#start_server ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/puma/runner.rb', line 151 def start_server min_t = @options[:min_threads] max_t = @options[:max_threads] server = Puma::Server.new app, @launcher.events, @options server.min_threads = min_t server.max_threads = max_t server.inherit_binder @launcher.binder if @options[:mode] == :tcp server.tcp_mode! end unless development? server.leak_stack_on_error = false end server end |