Class: God::Conditions::ProcessRunning

Inherits:
PollCondition show all
Defined in:
lib/god/conditions/process_running.rb

Instance Attribute Summary collapse

Attributes inherited from PollCondition

#interval

Attributes inherited from Behavior

#watch

Instance Method Summary collapse

Methods inherited from PollCondition

#after, #before

Methods inherited from God::Condition

generate

Methods inherited from Behavior

#after_restart, #after_start, #after_stop, #before_restart, #before_start, #before_stop, generate, #prepare

Instance Attribute Details

#runningObject

Returns the value of attribute running.



5
6
7
# File 'lib/god/conditions/process_running.rb', line 5

def running
  @running
end

Instance Method Details

#testObject



14
15
16
17
18
19
20
21
# File 'lib/god/conditions/process_running.rb', line 14

def test
  return !self.running unless File.exist?(self.watch.pid_file)
  
  pid = File.read(self.watch.pid_file).strip
  active = System::Process.new(pid).exists?
  
  (self.running && active) || (!self.running && !active)
end

#valid?Boolean

Returns:



7
8
9
10
11
12
# File 'lib/god/conditions/process_running.rb', line 7

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
end