4 # Condition Symbol :process_running
7 # Trigger when a process is running or not running depending on attributes.
11 # +pid_file+ is the pid file of the process in question. Automatically
12 # populated for Watches.
13 # +running" specifies whether you want to trigger if the process is
14 # running (true) or whether it is not running (false)
18 # Trigger if process IS NOT running (from a Watch):
20 # on.condition(:process_running) do |c|
24 # Trigger if process IS running (from a Watch):
26 # on.condition(:process_running) do |c|
30 # Non-Watch Tasks must specify a PID file:
32 # on.condition(:process_running) do |c|
34 # c.pid_file = "/var/run/mongrel.3000.pid"
36 class ProcessRunning < PollCondition
37 attr_accessor :running
41 valid &= complain("Attribute 'pid_file' must be specified", self) if self.watch.pid_file.nil?
42 valid &= complain("Attribute 'running' must be specified", self) if self.running.nil?
49 unless File.exist?(self.watch.pid_file)
50 self.info << "#{self.watch.name} #{self.class.name}: no such pid file: #{self.watch.pid_file}"
54 pid = File.read(self.watch.pid_file).strip
55 active = System::Process.new(pid).exists?
57 if (self.running && active)
58 self.info << "process is running"
60 elsif (!self.running && !active)
61 self.info << "process is not running"
65 self.info << "process is not running"
67 self.info << "process is running"