Class: God::Conditions::ProcessRunning
- Inherits:
-
PollCondition
- Object
- Behavior
- God::Condition
- PollCondition
- God::Conditions::ProcessRunning
- Defined in:
- lib/god/conditions/process_running.rb
Overview
Trigger when a process is running or not running depending on attributes.
Examples
# Trigger if process IS NOT running.
on.condition(:process_running) do |c|
c.running = false
end
# Trigger if process IS running.
on.condition(:process_running) do |c|
c.running = true
end
# Non-Watch Tasks must specify a PID file.
on.condition(:process_running) do |c|
c.running = false
c.pid_file = "/var/run/mongrel.3000.pid"
end
Instance Attribute Summary collapse
-
#pid_file ⇒ Object
Public: The String PID file location of the process in question.
-
#running ⇒ Object
Public: The Boolean specifying whether you want to trigger if the process is running (true) or if it is not running (false).
Attributes inherited from PollCondition
Attributes inherited from God::Condition
#info, #notify, #phase, #transition
Attributes inherited from Behavior
Instance Method Summary collapse
Methods inherited from PollCondition
Methods inherited from God::Condition
#friendly_name, generate, valid?
Methods inherited from Behavior
#after_restart, #after_start, #after_stop, #before_restart, #before_start, #before_stop, #friendly_name, generate
Methods included from God::Configurable
#base_name, complain, #complain, #friendly_name, #prepare, #reset
Instance Attribute Details
#pid_file ⇒ Object
Public: The String PID file location of the process in question. Automatically populated for Watches.
31 32 33 |
# File 'lib/god/conditions/process_running.rb', line 31 def pid_file @pid_file end |
#running ⇒ Object
Public: The Boolean specifying whether you want to trigger if the process is running (true) or if it is not running (false).
27 28 29 |
# File 'lib/god/conditions/process_running.rb', line 27 def running @running end |
Instance Method Details
#pid ⇒ Object
33 34 35 |
# File 'lib/god/conditions/process_running.rb', line 33 def pid pid_file ? File.read(pid_file).strip.to_i : watch.pid end |
#test ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/god/conditions/process_running.rb', line 44 def test self.info = [] pid = self.pid active = pid && System::Process.new(pid).exists? if running && active info.push('process is running') true elsif !running && !active info.push('process is not running') true else info.push('process is not running') if running false end end |
#valid? ⇒ Boolean
37 38 39 40 41 42 |
# File 'lib/god/conditions/process_running.rb', line 37 def valid? valid = true valid &= complain("Attribute 'pid_file' must be specified", self) if pid_file.nil? && watch.pid_file.nil? valid &= complain("Attribute 'running' must be specified", self) if running.nil? valid end |