diff --git a/lib/puma/cluster.rb b/lib/puma/cluster.rb index 3b301bb063..c43e38b4a0 100644 --- a/lib/puma/cluster.rb +++ b/lib/puma/cluster.rb @@ -164,16 +164,6 @@ def check_workers ].compact.min end - def wakeup! - return unless @wakeup - - begin - @wakeup.write "!" unless @wakeup.closed? - rescue SystemCallError, IOError - Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue - end - end - def worker(index, master) @workers = [] diff --git a/lib/puma/cluster/worker.rb b/lib/puma/cluster/worker.rb index 05991dda2d..53720f4d37 100644 --- a/lib/puma/cluster/worker.rb +++ b/lib/puma/cluster/worker.rb @@ -168,16 +168,6 @@ def spawn_worker(idx) @launcher.config.run_hooks :after_worker_fork, idx, @launcher.events pid end - - def wakeup! - return unless @wakeup - - begin - @wakeup.write "!" unless @wakeup.closed? - rescue SystemCallError, IOError - Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue - end - end end end end diff --git a/lib/puma/runner.rb b/lib/puma/runner.rb index 30c4a89b2c..473b4ce59e 100644 --- a/lib/puma/runner.rb +++ b/lib/puma/runner.rb @@ -15,6 +15,16 @@ def initialize(cli, events) @app = nil @control = nil @started_at = Time.now + @wakeup = nil + end + + def wakeup! + return unless @wakeup + + @wakeup.write "!" unless @wakeup.closed? + + rescue SystemCallError, IOError + Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue end def development? @@ -108,9 +118,7 @@ def redirect_io append = @options[:redirect_append] if stdout - unless Dir.exist?(File.dirname(stdout)) - raise "Cannot redirect STDOUT to #{stdout}" - end + ensure_output_directory_exists(stdout, 'STDOUT') STDOUT.reopen stdout, (append ? "a" : "w") STDOUT.puts "=== puma startup: #{Time.now} ===" @@ -118,9 +126,7 @@ def redirect_io end if stderr - unless Dir.exist?(File.dirname(stderr)) - raise "Cannot redirect STDERR to #{stderr}" - end + ensure_output_directory_exists(stderr, 'STDERR') STDERR.reopen stderr, (append ? "a" : "w") STDERR.puts "=== puma startup: #{Time.now} ===" @@ -159,5 +165,12 @@ def start_server server.inherit_binder @launcher.binder server end + + private + def ensure_output_directory_exists(path, io_name) + unless Dir.exist?(File.dirname(path)) + raise "Cannot redirect #{io_name} to #{path}" + end + end end end