Class: God::Conditions::ProcessExits
- Inherits:
-
EventCondition
- Object
- Behavior
- God::Condition
- EventCondition
- God::Conditions::ProcessExits
- Defined in:
- lib/god/conditions/process_exits.rb
Overview
Condition Symbol :process_exits Type: Event
Trigger when a process exits.
Paramaters
Required
+pid_file+ is the pid file of the process in question. Automatically
populated for Watches.
Examples
Trigger if process exits (from a Watch):
on.condition(:process_exits)
Trigger if process exits:
on.condition(:process_exits) do |c|
c.pid_file = "/var/run/mongrel.3000.pid"
end
Instance Attribute Summary collapse
-
#pid_file ⇒ Object
Returns the value of attribute pid_file.
Attributes inherited from God::Condition
#info, #notify, #phase, #transition
Attributes inherited from Behavior
Instance Method Summary collapse
- #deregister ⇒ Object
-
#initialize ⇒ ProcessExits
constructor
A new instance of ProcessExits.
- #pid ⇒ Object
- #register ⇒ Object
- #valid? ⇒ Boolean
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
Constructor Details
#initialize ⇒ ProcessExits
Returns a new instance of ProcessExits.
28 29 30 |
# File 'lib/god/conditions/process_exits.rb', line 28 def initialize self.info = "process exited" end |
Instance Attribute Details
#pid_file ⇒ Object
Returns the value of attribute pid_file.
26 27 28 |
# File 'lib/god/conditions/process_exits.rb', line 26 def pid_file @pid_file end |
Instance Method Details
#deregister ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/god/conditions/process_exits.rb', line 57 def deregister pid = self.pid if pid EventHandler.deregister(pid, :proc_exit) msg = "#{self.watch.name} deregistered 'proc_exit' event for pid #{pid}" applog(self.watch, :info, msg) else pid_file_location = self.pid_file || self.watch.pid_file applog(self.watch, :error, "#{self.watch.name} could not deregister: no cached PID or PID file #{pid_file_location} (#{self.base_name})") end end |
#pid ⇒ Object
36 37 38 |
# File 'lib/god/conditions/process_exits.rb', line 36 def pid self.pid_file ? File.read(self.pid_file).strip.to_i : self.watch.pid end |
#register ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/god/conditions/process_exits.rb', line 40 def register pid = self.pid begin EventHandler.register(pid, :proc_exit) do |extra| formatted_extra = extra.size > 0 ? " #{extra.inspect}" : "" self.info = "process #{pid} exited#{formatted_extra}" self.watch.trigger(self) end msg = "#{self.watch.name} registered 'proc_exit' event for pid #{pid}" applog(self.watch, :info, msg) rescue StandardError raise EventRegistrationFailedError.new end end |
#valid? ⇒ Boolean
32 33 34 |
# File 'lib/god/conditions/process_exits.rb', line 32 def valid? true end |