From 4aab1f35b08135e9bab38d3313a71162475e1691 Mon Sep 17 00:00:00 2001 From: Tom Preston-Werner Date: Sun, 24 Jun 2007 11:24:43 -0700 Subject: [PATCH] convert ProcessNotRunning to use System::Process --- lib/god/conditions/process_not_running.rb | 10 +--------- lib/god/system/process.rb | 3 ++- site/index.html | 26 ++++++++++++++++++++++++-- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/lib/god/conditions/process_not_running.rb b/lib/god/conditions/process_not_running.rb index 7e5bdfd..feed257 100644 --- a/lib/god/conditions/process_not_running.rb +++ b/lib/god/conditions/process_not_running.rb @@ -14,16 +14,8 @@ module God return false unless File.exist?(self.pid_file) pid = File.open(self.pid_file).read.strip - process_running?(pid) + System::Process.new(pid).exists? end - - private - - def process_running?(pid) - cmd_name = RUBY_PLATFORM =~ /solaris/i ? "args" : "command" - ps_output = `ps -o #{cmd_name}= -p #{pid}` - !ps_output.strip.empty? - end end end diff --git a/lib/god/system/process.rb b/lib/god/system/process.rb index e2c0e72..76843bb 100644 --- a/lib/god/system/process.rb +++ b/lib/god/system/process.rb @@ -8,7 +8,8 @@ module God # Return true if this process is running, false otherwise def exists? - !ps_string('command').empty? + cmd_name = RUBY_PLATFORM =~ /solaris/i ? "args" : "command" + !ps_string(cmd_name).empty? end # Memory usage in kilobytes (resident set size) diff --git a/site/index.html b/site/index.html index ab12153..b9824d3 100644 --- a/site/index.html +++ b/site/index.html @@ -145,7 +145,7 @@ ul.features li { pre { - line-height: 1.5; + line-height: 1.3; border: 1px solid #ccc; padding: 1em; background-color: #efefef; @@ -347,7 +347,29 @@ end

God was designed from the start to allow you to easily write your own custom conditions, making it simple to add tests that are application specific.

-
+
module God
+  module Conditions
+    
+    class ProcessNotRunning < Condition
+      attr_accessor :pid_file
+      
+      def valid?
+        valid = true
+        valid &= complain("You must specify the 'pid_file' attribute 
+          for :process_not_running") if self.pid_file.nil?
+        valid
+      end
+    
+      def test
+        return false unless File.exist?(self.pid_file)
+        
+        pid = File.open(self.pid_file).read.strip
+        System::Process.new(pid).exists?
+      end
+    end
+    
+  end
+end