lib/god/conditions/process_running.rb in god-0.4.3 vs lib/god/conditions/process_running.rb in god-0.5.0

- old
+ new

@@ -4,21 +4,39 @@ class ProcessRunning < PollCondition attr_accessor :running def valid? valid = true - valid &= complain("You must specify the 'pid_file' attribute on the Watch for :process_running") if self.watch.pid_file.nil? - valid &= complain("You must specify the 'running' attribute for :process_running") if self.running.nil? + valid &= complain("Attribute 'pid_file' must be specified", self) if self.watch.pid_file.nil? + valid &= complain("Attribute 'running' must be specified", self) if self.running.nil? valid end def test - return !self.running unless File.exist?(self.watch.pid_file) + self.info = [] + unless File.exist?(self.watch.pid_file) + self.info << "#{self.watch.name} #{self.class.name}: no such pid file: #{self.watch.pid_file}" + return !self.running + end + pid = File.read(self.watch.pid_file).strip active = System::Process.new(pid).exists? - (self.running && active) || (!self.running && !active) + if (self.running && active) + self.info << "process is running" + true + elsif (!self.running && !active) + self.info << "process is not running" + true + else + if self.running + self.info << "process is not running" + else + self.info << "process is running" + end + false + end end end end end \ No newline at end of file