class Process::Daemon::Controller
def stop_by_terminate_or_kill(pgid)
def stop_by_terminate_or_kill(pgid) # TERM/KILL loop - if the daemon didn't die easily, shoot it a few more times. (STOP_ATTEMPTS+1).times do |attempt| break unless ProcessFile.running(@daemon) # SIGKILL gets sent on the last attempt. signal_name = (attempt < STOP_ATTEMPTS) ? "TERM" : "KILL" @output.puts Rainbow("Sending #{signal_name} to process group #{pgid}...").red Process.kill(signal_name, pgid) # We iterate quickly to start with, and slow down if the process seems unresponsive. timeout = STOP_PERIOD + (attempt.to_f / STOP_ATTEMPTS) * STOP_WAIT_FACTOR @output.puts Rainbow("Waiting for #{timeout.round(1)}s for daemon to terminate...").blue sleep(timeout) end end