4 # Condition Symbol :process_exits
7 # Trigger when a process exits.
11 # +pid_file+ is the pid file of the process in question. Automatically
12 # populated for Watches.
16 # Trigger if process exits (from a Watch):
18 # on.condition(:process_exits)
20 # Trigger if process exits:
22 # on.condition(:process_exits) do |c|
23 # c.pid_file = "/var/run/mongrel.3000.pid"
25 class ProcessExits < EventCondition
27 self.info = "process exited"
32 valid &= complain("Attribute 'pid_file' must be specified", self) if self.watch.pid_file.nil?
37 pid = File.read(self.watch.pid_file).strip.to_i
40 EventHandler.register(pid, :proc_exit) do |extra|
41 self.info = "process #{pid} exited #{extra.inspect}"
45 msg = "#{self.watch.name} registered 'proc_exit' event for pid #{pid}"
46 applog(self.watch, :info, msg)
48 raise EventRegistrationFailedError.new
53 if File.exist?(self.watch.pid_file)
54 pid = File.read(self.watch.pid_file).strip.to_i
55 EventHandler.deregister(pid, :proc_exit)
57 msg = "#{self.watch.name} deregistered 'proc_exit' event for pid #{pid}"
58 applog(self.watch, :info, msg)
60 applog(self.watch, :error, "#{self.watch.name} could not deregister: no such PID file #{self.watch.pid_file} (#{self.base_name})")