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:
parent
b59db28a6c
commit
a585772402
3 changed files with 33 additions and 24 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue