Skip to content

Commit

Permalink
Remove debug logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Jan 29, 2025
1 parent 4d43c7f commit 7ab9a01
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
3 changes: 0 additions & 3 deletions lib/thin/daemonizing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def daemonize
write_pid_file

at_exit do
$stderr.puts "Exiting daemonized server..."
log_info "Exiting!"
remove_pid_file
end
Expand Down Expand Up @@ -179,7 +178,6 @@ def remove_pid_file
end

def write_pid_file
$stderr.puts "Writing PID #{Process.pid} to #{@pid_file}..."
log_info "Writing PID to #{@pid_file}"
open(@pid_file,"w") { |f| f.write(Process.pid) }
File.chmod(0644, @pid_file)
Expand All @@ -192,7 +190,6 @@ def remove_stale_pid_file
raise PidFileExist, "#{@pid_file} already exists, seems like it's already running (process ID: #{pid}). " +
"Stop the process or delete #{@pid_file}."
else
$stderr.puts "Deleting stale PID file #{@pid_file}..."
log_info "Deleting stale PID file #{@pid_file}"
remove_pid_file
end
Expand Down
28 changes: 16 additions & 12 deletions spec/daemonizing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,26 +87,21 @@ def name
end

it 'should kill process in pid file' do
$stderr.puts "Pid file should not exist: #{subject.pid_file}"
expect(File.exist?(subject.pid_file)).to be_falsey

$stderr.puts "Forking..."
pid = fork do
subject.daemonize
sleep
end

wait_for_server_to_start

$stderr.puts "Pid file should exist: #{subject.pid_file} pid=#{pid}"
expect(File.exist?(subject.pid_file)).to be_truthy

$stderr.puts "Killing..."
silence_stream STDOUT do
subject.kill(1)
end

$stderr.puts "Waiting for process to die..."
Process.wait(pid)
expect(File.exist?(subject.pid_file)).to be_falsey
end
Expand Down Expand Up @@ -197,14 +192,23 @@ def name
private

def wait_for_server_to_start
$stderr.puts "Waiting for server to start... pid_file=#{subject.pid_file}"
until File.exist?(subject.pid_file)
$stderr.puts "Sleeping..."
sleep(1)

File.read(subject.log_file).each_line do |line|
$stderr.puts line
count = 1

while true
break if File.exist?(subject.pid_file)

sleep(count * 0.1)

if count > 10
$stderr.puts "Dumping log file #{subject.log_file}:"
File.foreach(subject.log_file) do |line|
$stderr.puts line
end

raise "Server did not start"
end

count += 1
end
end
end

0 comments on commit 7ab9a01

Please sign in to comment.