Implement Foreman::Process#kill,detach,alive?,dead?

This commit is contained in:
brainopia
2012-01-22 22:07:01 +04:00
parent 047f106d48
commit 241b91a0d5
2 changed files with 19 additions and 2 deletions

View File

@@ -74,7 +74,7 @@ private ######################################################################
def kill_all(signal="SIGTERM")
running_processes.each do |pid, process|
info "sending #{signal} to pid #{pid}"
Process.kill(signal, pid) rescue Errno::ESRCH
process.kill signal
end
end

View File

@@ -25,6 +25,24 @@ class Foreman::Process
"%s.%s" % [ entry.name, num ]
end
def kill(signal)
pid && Process.kill(signal, pid)
rescue Errno::ESRCH
false
end
def detach
pid && Process.detach(pid)
end
def alive?
kill(0)
end
def dead?
!alive?
end
private
def fork_with_io(command)
@@ -65,5 +83,4 @@ private
ensure
ENV.replace original
end
end