implemented state based lifecycle
[god.git] / lib / god / conditions / process_running.rb
blob2fbf97ebd9524c91e58480a7e6da66321a7cc157
1 module God
2   module Conditions
3     
4     class ProcessRunning < PollCondition
5       attr_accessor :pid_file, :running
6       
7       def valid?
8         valid = true
9         valid &= complain("You must specify the 'pid_file' attribute for :process_running") if self.pid_file.nil?
10         valid &= complain("You must specify the 'running' attribute for :process_running") if self.running.nil?
11         valid
12       end
13     
14       def test
15         return !self.running unless File.exist?(self.pid_file)
16         
17         pid = File.open(self.pid_file).read.strip
18         active = System::Process.new(pid).exists?
19         
20         (self.running && active) || (!self.running && !active)
21       end
22     end
23     
24   end
25 end