Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 9 additions & 37 deletions lib/daemon_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -455,44 +455,10 @@ def daemonization_timed_out(pid)

# Aborts a daemon that we tried to start, but timed out.
def abort_start(pid:, is_direct_child:)
begin
debug "Killing process #{pid}"
Process.kill("SIGTERM", pid)
rescue SystemCallError
end

begin
timeoutable(@start_abort_timeout) do
allow_timeout do
if is_direct_child
begin
debug "Waiting directly for process #{pid}"
Process.waitpid(pid)
rescue SystemCallError
end

# The daemon may have:
# 1. Written a PID file before forking. We delete this PID file.
# -OR-
# 2. It might have forked (and written a PID file) right before
# we terminated it. We'll want the fork to stay alive rather
# than going through the (complicated) trouble of killing it.
# Don't touch the PID file.
pid2 = read_pid_file
debug "PID file contains #{pid2.inspect}"
delete_pid_file if pid == pid2
else
debug "Waiting until daemon is no longer running"
wait_until { !daemon_is_running? }
end
end
end
rescue Timeout::Error
begin
Process.kill("SIGKILL", pid)
rescue SystemCallError
end
debug "Killing process #{pid}"
Process.kill("SIGTERM", pid)

block = proc do
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than a proc, you should split this up to a separate method for better readability.

allow_timeout do
if is_direct_child
begin
Expand All @@ -517,6 +483,12 @@ def abort_start(pid:, is_direct_child:)
end
end
end

timeoutable(@start_abort_timeout, &block)
rescue Timeout::Error
Process.kill("SIGKILL", pid)
block.call
rescue SystemCallError
end

def save_log_file_information
Expand Down