lib/puma/runner.rb in piesync-puma-3.12.6.1 vs lib/puma/runner.rb in piesync-puma-5.4.0.1

- old
+ new

@@ -12,16 +12,13 @@ @launcher = cli @events = events @options = cli.options @app = nil @control = nil + @started_at = Time.now end - def daemon? - @options[:daemon] - end - def development? @options[:environment] == "development" end def test? @@ -30,11 +27,12 @@ def log(str) @events.log str end - def before_restart + # @version 5.0.0 + def stop_control @control.stop(true) if @control end def error(str) @events.error str @@ -48,40 +46,31 @@ 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 + token = nil if token.empty? || token == 'none' end - control = Puma::Server.new app, @launcher.events - control.min_threads = 0 - control.max_threads = 1 + app = Puma::App::Status.new @launcher, token - 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 = Puma::Server.new app, @launcher.events, + { min_threads: 0, max_threads: 1, queue_requests: false } - control.add_unix_listener path, mask - else - error "Invalid control URI: #{str}" - end + control.binder.parse [str], self, 'Starting control server' - control.run + control.run thread_name: 'control' @control = control end + # @version 5.0.0 + def close_control_listeners + @control.binder.close_listeners if @control + end + + # @!attribute [r] ruby_engine def ruby_engine if !defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby" "ruby #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}" else if defined?(RUBY_ENGINE_VERSION) @@ -95,16 +84,19 @@ 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']}" + log "* Puma version: #{Puma::Const::PUMA_VERSION} (#{ruby_engine}) (\"#{Puma::Const::CODE_NAME}\")" + log "* Min threads: #{min_t}" + log "* Max threads: #{max_t}" + log "* Environment: #{ENV['RACK_ENV']}" - if @options[:mode] == :tcp - log "* Mode: Lopez Express (tcp)" + if mode == "cluster" + log "* Master PID: #{Process.pid}" + else + log "* PID: #{Process.pid}" end end def redirected_io? @options[:redirect_stdout] || @options[:redirect_stderr] @@ -119,66 +111,53 @@ 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} ===" + STDOUT.flush unless STDOUT.sync 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} ===" + STDERR.flush unless STDERR.sync end + + if @options[:mutate_stdout_and_stderr_to_sync_on_write] + STDOUT.sync = true + STDERR.sync = true + end end 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.message}" raise e end @launcher.binder.parse @options[:binds], self end + # @!attribute [r] app def app @app ||= @launcher.config.app end 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 - - if @options[:early_hints] - server.early_hints = true - end - - unless development? || test? - server.leak_stack_on_error = false - end - server end end end