lib/process/daemon/controller.rb in process-daemon-1.0.0 vs lib/process/daemon/controller.rb in process-daemon-1.0.1
- old
+ new
@@ -186,12 +186,16 @@
@daemon.tail_log($stderr)
return
end
pgid = -Process.getpgid(pid)
-
+
+ # Stop by interrupt sends a single interrupt and waits for the process to terminate:
unless stop_by_interrupt(pgid)
+ # If the process is still running, we try sending SIGTERM followed by SIGKILL:
+ @output.puts Rainbow("** Daemon did not stop gracefully after #{@stop_timeout}s **").red
+
stop_by_terminate_or_kill(pgid)
end
# If after doing our best the @daemon is still running (pretty odd)...
if ProcessFile.running(@daemon)
@@ -205,10 +209,11 @@
ProcessFile.clear(@daemon)
end
private
+ # Returns true if the process was stopped.
def stop_by_interrupt(pgid)
running = true
# Interrupt the process group:
Process.kill("INT", pgid)
@@ -217,10 +222,10 @@
if running = ProcessFile.running(@daemon)
sleep STOP_PERIOD
end
end
- return running
+ return !running
end
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|