From 9808a334af7cc461c1431b412236a8e5bf3e51a9 Mon Sep 17 00:00:00 2001 From: Tom Werner Date: Tue, 14 Aug 2007 14:47:58 -0700 Subject: [PATCH] fix byte-centric sugar (kb is canonical not bytes); make god binary pid generation optional --- History.txt | 5 +++-- Rakefile | 5 +++++ bin/god | 11 ++++------- lib/god/sugar.rb | 12 +++--------- site/index.html | 2 +- test/test_sugar.rb | 17 ++++++----------- 6 files changed, 22 insertions(+), 30 deletions(-) diff --git a/History.txt b/History.txt index 5e7c193..b72032d 100644 --- a/History.txt +++ b/History.txt @@ -17,9 +17,10 @@ * Enhance god binary with better reporting * Fix synchronization bug in Timer (reported by Srini Panguluri) * Add Lambda condition for easy custom conditions [Mike Mintz] -* Add sugar for numerics (seconds, minutes, bytes, kilobytes, etc) -* Add PID and log file generation to god binary +* Add sugar for numerics (seconds, minutes, kilobytes, megabytes, percent, etc) +* Add optional PID and log file generation to god binary for daemon mode * Add God.load to do glob enabled loading +* Add -V option to god binary for detailed version/build info == 0.2.0 / 2007-07-18 diff --git a/Rakefile b/Rakefile index aae5b19..6571b1d 100644 --- a/Rakefile +++ b/Rakefile @@ -25,4 +25,9 @@ task :site do sh "scp -r site/* mojombo@god.rubyforge.org:/var/www/gforge-projects/god" end +desc "Upload site to Rubyforge" +task :site_edge do + sh "scp -r site/* mojombo@god.rubyforge.org:/var/www/gforge-projects/god/edge" +end + # vim: syntax=Ruby diff --git a/bin/god b/bin/god index e6acd89..9036a61 100755 --- a/bin/god +++ b/bin/god @@ -107,8 +107,6 @@ else begin require 'god' - # Dir.chdir "/" - log_file = options[:log] || "/dev/null" STDIN.reopen "/dev/null" @@ -129,9 +127,7 @@ else end puts "Resetting file descriptors" - - # Daemons.daemonize if options[:daemonize] - + puts "Loading config" load File.expand_path(options[:config]) @@ -141,8 +137,9 @@ else end end - pid_file = options[:pid] || "god.pid" - File.open(pid_file, 'w') { |f| f.write pid } + if options[:pid] + File.open(options[:pid], 'w') { |f| f.write pid } + end ::Process.detach pid diff --git a/lib/god/sugar.rb b/lib/god/sugar.rb index 6fba7ba..1179557 100644 --- a/lib/god/sugar.rb +++ b/lib/god/sugar.rb @@ -23,26 +23,20 @@ class Numeric alias :day :days - def bytes - self - end - - alias :byte :bytes - def kilobytes - self * 1024 + self end alias :kilobyte :kilobytes def megabytes - self * (1024 ** 2) + self * 1024 end alias :megabyte :megabytes def gigabytes - self * (1024 ** 3) + self * (1024 ** 2) end alias :gigabyte :gigabytes diff --git a/site/index.html b/site/index.html index 92dac4f..cd31089 100644 --- a/site/index.html +++ b/site/index.html @@ -332,7 +332,7 @@ end ... end -

Similar to start_if there is a restart_if command that groups conditions that should trigger a restart. The memory_usage condition will fail if the specified process is using too much memory. The maximum allowable amount of memory is specified with the above attribute (you can use the bytes, kilobytes, megabytes, or gigabytes helpers). The number of times the test needs to fail in order to trigger a restart is set with times. This can be either an integer or an array. An integer means it must fail that many times in a row while an array [x, y] means it must fail x times out of the last y tests.

+

Similar to start_if there is a restart_if command that groups conditions that should trigger a restart. The memory_usage condition will fail if the specified process is using too much memory. The maximum allowable amount of memory is specified with the above attribute (you can use the kilobytes, megabytes, or gigabytes helpers). The number of times the test needs to fail in order to trigger a restart is set with times. This can be either an integer or an array. An integer means it must fail that many times in a row while an array [x, y] means it must fail x times out of the last y tests.

    w.restart_if do |restart|
       ...
diff --git a/test/test_sugar.rb b/test/test_sugar.rb
index 95131f2..911a77f 100644
--- a/test/test_sugar.rb
+++ b/test/test_sugar.rb
@@ -21,24 +21,19 @@ class TestSugar < Test::Unit::TestCase
     assert_equal 86400, 1.day
   end
   
-  def test_bytes
-    assert_equal 1, 1.bytes
-    assert_equal 1, 1.byte
-  end
-  
   def test_kilobytes
-    assert_equal 1024, 1.kilobytes
-    assert_equal 1024, 1.kilobyte
+    assert_equal 1, 1.kilobytes
+    assert_equal 1, 1.kilobyte
   end
   
   def test_megabytes
-    assert_equal 1024 ** 2, 1.megabytes
-    assert_equal 1024 ** 2, 1.megabyte
+    assert_equal 1024, 1.megabytes
+    assert_equal 1024, 1.megabyte
   end
   
   def test_gigabytes
-    assert_equal 1024 ** 3, 1.gigabytes
-    assert_equal 1024 ** 3, 1.gigabyte
+    assert_equal 1024 ** 2, 1.gigabytes
+    assert_equal 1024 ** 2, 1.gigabyte
   end
   
   def test_percent
-- 
2.11.4.GIT