Permalink
Browse files

intial simple examples

  • Loading branch information...
1 parent 8f1537d commit 017ac1284c907088e402c4ec75db2a8b0fbcaf3b @jnewland committed Jul 8, 2008
Showing with 85 additions and 0 deletions.
  1. 0 README
  2. +1 −0 README.textile
  3. +4 −0 daemons/crashy_daemon.rb
  4. +4 −0 daemons/stable_daemon.rb
  5. +18 −0 leaky.god
  6. +27 −0 lib/god_test.rb
  7. +2 −0 pids/.gitignore
  8. +4 −0 scripts/crash_immediately.rb
  9. +4 −0 scripts/crashy.rb
  10. +4 −0 scripts/leaky.rb
  11. +4 −0 scripts/stable.rb
  12. +13 −0 simple.god
View
0 README
No changes.
View
@@ -0,0 +1 @@
+Some silly examples of some of the things you can do with God.
View
@@ -0,0 +1,4 @@
+require 'rubygems'
+require 'daemons'
+
+Daemons.run(File.dirname(__FILE__) + '/../scripts/crashy.rb', { :dir_mode => :normal, :dir => File.dirname(__FILE__) + '/../pids', :log_output => true })
View
@@ -0,0 +1,4 @@
+require 'rubygems'
+require 'daemons'
+
+Daemons.run(File.dirname(__FILE__) + '/../scripts/stable.rb', { :dir_mode => :normal, :dir => File.dirname(__FILE__) + '/../pids', :log_output => true })
View
@@ -0,0 +1,18 @@
+God.watch do |w|
+ w.name = "leaky"
+ w.interval = 5.second
+ w.start = 'ruby ' + File.dirname(__FILE__) + '/scripts/leaky.rb'
+
+ w.start_if do |start|
+ start.condition(:process_running) do |c|
+ c.running = false
+ end
+ end
+
+ w.restart_if do |restart|
+ restart.condition(:memory_usage) do |c|
+ c.above = 2.megabytes
+ end
+ end
+
+end
View
@@ -0,0 +1,27 @@
+class GodTest
+
+ def initialize(options = {})
+ @crashiness = options[:crashiness] || nil
+ @leakiness = options[:leakiness] || nil
+ @delay = options[:delay] || 30
+ run
+ end
+
+ def run
+ loop do
+ crash unless @crashiness.nil?
+ leak unless @leakiness.nil?
+ puts Time.now
+ sleep(@delay)
+ end
+ end
+
+ def crash
+ raise "Crash!" if rand(@crashiness) == 1 || @crashiness == 1
+ end
+
+ def leak
+ instance_variable_set("@leak#{rand(100000000)}".to_sym, (File.read(__FILE__) * @leakiness))
+ end
+
+end
View
@@ -0,0 +1,2 @@
+*.output
+*.pid
@@ -0,0 +1,4 @@
+$: << File.expand_path(File.dirname(__FILE__) + "/../lib")
+require 'god_test'
+
+GodTest.new(:crashiness => 1)
View
@@ -0,0 +1,4 @@
+$: << File.expand_path(File.dirname(__FILE__) + "/../lib")
+require 'god_test'
+
+GodTest.new(:crashiness => 5)
View
@@ -0,0 +1,4 @@
+$: << File.expand_path(File.dirname(__FILE__) + "/../lib")
+require 'god_test'
+
+GodTest.new(:leakiness => 100, :delay => 1)
View
@@ -0,0 +1,4 @@
+$: << File.expand_path(File.dirname(__FILE__) + "/../lib")
+require 'god_test'
+
+GodTest.new
View
@@ -0,0 +1,13 @@
+#The simplest possible watch
+God.watch do |w|
+ w.name = "stable"
+ w.interval = 30.seconds
+ w.start = 'ruby ' + File.dirname(__FILE__) + '/scripts/stable.rb'
+
+ w.start_if do |start|
+ start.condition(:process_running) do |c|
+ c.running = false
+ end
+ end
+
+end

0 comments on commit 017ac12

Please sign in to comment.