propogate netlink status to process exits condition
[god.git] / lib / god / conditions / process_exits.rb
blob787df202e18b6610215f72cda9bb57c98386ed09
1 module God
2   module Conditions
3     
4     class ProcessExits < EventCondition
5       def initialize
6         self.info = "process exited"
7       end
8       
9       def valid?
10         valid = true
11         valid &= complain("Attribute 'pid_file' must be specified", self) if self.watch.pid_file.nil?
12         valid
13       end
14     
15       def register
16         pid = File.read(self.watch.pid_file).strip.to_i
17         
18         begin
19           EventHandler.register(pid, :proc_exit) do |extra|
20             self.info = "process exited #{extra.inspect}"
21             Hub.trigger(self)
22           end
23         rescue StandardError
24           raise EventRegistrationFailedError.new
25         end
26       end
27       
28       def deregister
29         if File.exist?(self.watch.pid_file)
30           pid = File.read(self.watch.pid_file).strip.to_i
31           EventHandler.deregister(pid, :proc_exit)
32         else
33           applog(self.watch, :error, "#{self.watch.name} could not deregister: no such PID file #{self.watch.pid_file} (#{self.base_name})")
34         end
35       end
36     end
37     
38   end
39 end