diff --git a/lib/daemon_controller.rb b/lib/daemon_controller.rb index 5781094..0753bf2 100644 --- a/lib/daemon_controller.rb +++ b/lib/daemon_controller.rb @@ -464,27 +464,7 @@ def abort_start(pid:, is_direct_child:) 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 + wait_for_aborted_process(pid:, is_direct_child:) end end rescue Timeout::Error @@ -494,28 +474,32 @@ def abort_start(pid:, is_direct_child:) end allow_timeout do - if is_direct_child - begin - debug "Waiting directly for process #{pid}" - Process.waitpid(pid) - rescue SystemCallError - end + wait_for_aborted_process(pid:, is_direct_child:) + end + end + 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 + def wait_for_aborted_process(pid:, is_direct_child:) + 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