lib/bluepill/process.rb in bluepill-0.0.49 vs lib/bluepill/process.rb in bluepill-0.0.50

- old
+ new

@@ -30,11 +30,14 @@ :gid, :cache_actual_pid, :monitor_children, - :child_process_factory + :child_process_factory, + + :pid_command, + :auto_start ] attr_accessor :name, :watches, :triggers, :logger, :skip_ticks_until, :process_running attr_accessor *CONFIGURABLE_ATTRIBUTES attr_reader :children, :statistics @@ -213,12 +216,11 @@ def determine_initial_state if self.process_running?(true) self.state = 'up' else - # TODO: or "unmonitored" if bluepill was started in no auto-start mode. - self.state = 'down' + self.state = (auto_start == false) ? 'unmonitored' : 'down' # we need to check for false value end end def handle_user_command(cmd) case cmd @@ -336,10 +338,14 @@ def cache_actual_pid? !!@cache_actual_pid end def actual_pid + pid_command ? pid_from_command : pid_from_file + end + + def pid_from_file return @actual_pid if cache_actual_pid? && @actual_pid @actual_pid = begin if pid_file if File.exists?(pid_file) str = File.read(pid_file) @@ -348,9 +354,14 @@ logger.warning("pid_file #{pid_file} does not exist or cannot be read") nil end end end + end + + def pid_from_command + pid = %x{#{pid_command}}.strip + (pid =~ /\A\d+\z/) ? pid.to_i : nil end def actual_pid=(pid) @actual_pid = pid end