correct regression where monitoring thread crashed out

add logging
This commit is contained in:
Sam 2015-06-16 11:16:33 +10:00
parent 771eeea837
commit 0e4883a8ae
1 changed files with 16 additions and 13 deletions

View File

@ -50,9 +50,10 @@ class Demon::Base
"#{Rails.root}/tmp/pids/#{self.class.prefix}_#{@index}.pid"
end
def alive?
if @pid
Demon::Base.alive?(@pid)
def alive?(pid=nil)
pid ||= @pid
if pid
Demon::Base.alive?(pid)
else
false
end
@ -145,13 +146,11 @@ class Demon::Base
end
def self.alive?(pid)
begin
Process.kill(0, pid)
true
rescue
false
end
end
private
@ -169,11 +168,15 @@ class Demon::Base
def monitor_parent
Thread.new do
while true
begin
unless alive?(@parent_pid)
Process.kill "TERM", Process.pid
sleep 10
Process.kill "KILL", Process.pid
end
rescue => e
STDERR.puts "URGENT monitoring thread had an exception #{e}"
end
sleep 1
end
end