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, :pid_file
40 self.watch.pid || File.read(self.pid_file).strip.to_i
45 valid &= complain("Attribute 'pid_file' must be specified", self) if self.watch.pid_file.nil? && self.pid_file.nil?
46 valid &= complain("Attribute 'running' must be specified", self) if self.running.nil?
53 # unless File.exist?(self.watch.pid_file)
54 # self.info << "#{self.watch.name} #{self.class.name}: no such pid file: #{self.watch.pid_file}"
55 # return !self.running
59 active = pid && System::Process.new(pid).exists?
61 if (self.running && active)
62 self.info << "process is running"
64 elsif (!self.running && !active)
65 self.info << "process is not running"
69 self.info << "process is not running"
71 self.info << "process is running"