1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Launcher: privatize write_pid, use log

This commit is contained in:
Nate Berkopec 2019-09-20 11:51:57 +02:00
parent b59db28a6c
commit a585772402
No known key found for this signature in database
GPG key ID: BDD7A4B8E43906A6
3 changed files with 33 additions and 24 deletions

View file

@ -126,19 +126,6 @@ module Puma
File.unlink(path) if path && File.exist?(path)
end
# If configured, write the pid of the current process out
# to a file.
def write_pid
path = @options[:pidfile]
return unless path
File.open(path, 'w') { |f| f.puts Process.pid }
cur = Process.pid
at_exit do
delete_pidfile if cur == Process.pid
end
end
# Begin async shutdown of the server
def halt
@status = :halt
@ -226,6 +213,19 @@ module Puma
private
# If configured, write the pid of the current process out
# to a file.
def write_pid
path = @options[:pidfile]
return unless path
File.open(path, 'w') { |f| f.puts Process.pid }
cur = Process.pid
at_exit do
delete_pidfile if cur == Process.pid
end
end
def reload_worker_directory
@runner.reload_worker_directory if @runner.respond_to?(:reload_worker_directory)
end
@ -331,15 +331,15 @@ module Puma
def log_thread_status
Thread.list.each do |thread|
@events.log "Thread TID-#{thread.object_id.to_s(36)} #{thread['label']}"
log "Thread TID-#{thread.object_id.to_s(36)} #{thread['label']}"
logstr = "Thread: TID-#{thread.object_id.to_s(36)}"
logstr += " #{thread.name}" if thread.respond_to?(:name)
@events.log logstr
log logstr
if thread.backtrace
@events.log thread.backtrace.join("\n")
log thread.backtrace.join("\n")
else
@events.log "<no backtrace available>"
log "<no backtrace available>"
end
end
end

View file

@ -33,13 +33,6 @@ class TestCLI < Minitest::Test
@ready.close
end
def test_pid_file
cli = Puma::CLI.new ["--pidfile", @tmp_path]
cli.launcher.write_pid
assert_equal File.read(@tmp_path).strip.to_i, Process.pid
end
def test_control_for_tcp
tcp = UniquePort.call
cntl = UniquePort.call

View file

@ -63,6 +63,22 @@ class TestLauncher < Minitest::Test
assert_match "Thread TID", events.stdout.read
end
def test_pid_file
tmp_file = Tempfile.new("puma-test")
tmp_path = tmp_file.path
tmp_file.close!
conf = Puma::Configuration.new do |c|
c.pidfile tmp_path
end
launcher(conf).write_state
assert_equal File.read(tmp_path).strip.to_i, Process.pid
File.unlink tmp_path
end
private
def events