god 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. data/Announce.txt +6 -6
  2. data/Gemfile +2 -0
  3. data/History.txt +19 -2
  4. data/{README.txt → LICENSE} +0 -37
  5. data/README.md +31 -0
  6. data/Rakefile +80 -38
  7. data/bin/god +21 -21
  8. data/doc/god.asciidoc +1487 -0
  9. data/doc/intro.asciidoc +20 -0
  10. data/ext/god/extconf.rb +3 -3
  11. data/ext/god/kqueue_handler.c +18 -18
  12. data/ext/god/netlink_handler.c +31 -31
  13. data/god.gemspec +24 -16
  14. data/lib/god.rb +261 -204
  15. data/lib/god/behavior.rb +14 -14
  16. data/lib/god/behaviors/clean_pid_file.rb +5 -5
  17. data/lib/god/behaviors/clean_unix_socket.rb +10 -10
  18. data/lib/god/behaviors/notify_when_flapping.rb +12 -12
  19. data/lib/god/cli/command.rb +59 -46
  20. data/lib/god/cli/run.rb +33 -37
  21. data/lib/god/cli/version.rb +6 -6
  22. data/lib/god/compat19.rb +1 -4
  23. data/lib/god/condition.rb +21 -21
  24. data/lib/god/conditions/always.rb +19 -6
  25. data/lib/god/conditions/complex.rb +18 -18
  26. data/lib/god/conditions/cpu_usage.rb +14 -14
  27. data/lib/god/conditions/degrading_lambda.rb +8 -8
  28. data/lib/god/conditions/disk_usage.rb +5 -5
  29. data/lib/god/conditions/flapping.rb +23 -23
  30. data/lib/god/conditions/http_response_code.rb +35 -19
  31. data/lib/god/conditions/lambda.rb +2 -2
  32. data/lib/god/conditions/memory_usage.rb +13 -13
  33. data/lib/god/conditions/process_exits.rb +14 -20
  34. data/lib/god/conditions/process_running.rb +16 -25
  35. data/lib/god/conditions/socket_responding.rb +132 -0
  36. data/lib/god/conditions/tries.rb +10 -10
  37. data/lib/god/configurable.rb +10 -10
  38. data/lib/god/contact.rb +20 -20
  39. data/lib/god/contacts/email.rb +7 -4
  40. data/lib/god/contacts/jabber.rb +1 -1
  41. data/lib/god/driver.rb +96 -64
  42. data/lib/god/errors.rb +9 -9
  43. data/lib/god/event_handler.rb +19 -19
  44. data/lib/god/event_handlers/dummy_handler.rb +4 -4
  45. data/lib/god/event_handlers/kqueue_handler.rb +3 -3
  46. data/lib/god/event_handlers/netlink_handler.rb +2 -2
  47. data/lib/god/logger.rb +13 -13
  48. data/lib/god/metric.rb +50 -22
  49. data/lib/god/process.rb +53 -52
  50. data/lib/god/registry.rb +7 -7
  51. data/lib/god/simple_logger.rb +14 -14
  52. data/lib/god/socket.rb +11 -11
  53. data/lib/god/sugar.rb +30 -15
  54. data/lib/god/sys_logger.rb +2 -2
  55. data/lib/god/system/portable_poller.rb +8 -8
  56. data/lib/god/system/process.rb +8 -8
  57. data/lib/god/system/slash_proc_poller.rb +13 -13
  58. data/lib/god/task.rb +237 -188
  59. data/lib/god/timeline.rb +5 -5
  60. data/lib/god/trigger.rb +11 -11
  61. data/lib/god/watch.rb +205 -53
  62. data/test/configs/child_events/child_events.god +5 -5
  63. data/test/configs/child_events/simple_server.rb +1 -1
  64. data/test/configs/child_polls/child_polls.god +4 -4
  65. data/test/configs/child_polls/simple_server.rb +4 -4
  66. data/test/configs/complex/complex.god +7 -7
  67. data/test/configs/complex/simple_server.rb +1 -1
  68. data/test/configs/contact/contact.god +1 -1
  69. data/test/configs/contact/simple_server.rb +1 -1
  70. data/test/configs/daemon_events/daemon_events.god +5 -5
  71. data/test/configs/daemon_events/simple_server.rb +1 -1
  72. data/test/configs/daemon_events/simple_server_stop.rb +1 -1
  73. data/test/configs/daemon_polls/daemon_polls.god +3 -3
  74. data/test/configs/daemon_polls/simple_server.rb +1 -1
  75. data/test/configs/degrading_lambda/degrading_lambda.god +3 -3
  76. data/test/configs/keepalive/keepalive.god +9 -0
  77. data/test/configs/keepalive/keepalive.rb +12 -0
  78. data/test/configs/lifecycle/lifecycle.god +2 -2
  79. data/test/configs/matias/matias.god +6 -6
  80. data/test/configs/real.rb +7 -7
  81. data/test/configs/running_load/running_load.god +2 -2
  82. data/test/configs/stop_options/simple_server.rb +1 -1
  83. data/test/configs/stress/simple_server.rb +1 -1
  84. data/test/configs/stress/stress.god +2 -2
  85. data/test/configs/task/task.god +5 -5
  86. data/test/configs/test.rb +7 -7
  87. data/test/helper.rb +8 -8
  88. data/test/test_behavior.rb +3 -3
  89. data/test/test_campfire.rb +1 -2
  90. data/test/test_condition.rb +10 -10
  91. data/test/test_conditions_disk_usage.rb +12 -12
  92. data/test/test_conditions_http_response_code.rb +24 -24
  93. data/test/test_conditions_process_running.rb +7 -7
  94. data/test/test_conditions_socket_responding.rb +122 -0
  95. data/test/test_conditions_tries.rb +12 -12
  96. data/test/test_contact.rb +19 -19
  97. data/test/test_driver.rb +17 -3
  98. data/test/test_event_handler.rb +12 -12
  99. data/test/test_god.rb +195 -117
  100. data/test/test_handlers_kqueue_handler.rb +4 -4
  101. data/test/test_jabber.rb +1 -1
  102. data/test/test_logger.rb +17 -17
  103. data/test/test_metric.rb +16 -16
  104. data/test/test_process.rb +47 -41
  105. data/test/test_prowl.rb +1 -1
  106. data/test/test_registry.rb +2 -2
  107. data/test/test_socket.rb +3 -3
  108. data/test/test_sugar.rb +7 -7
  109. data/test/test_system_portable_poller.rb +1 -1
  110. data/test/test_system_process.rb +5 -5
  111. data/test/test_task.rb +57 -57
  112. data/test/test_timeline.rb +8 -8
  113. data/test/test_trigger.rb +16 -16
  114. data/test/test_watch.rb +69 -62
  115. metadata +182 -69
  116. data/lib/god/dependency_graph.rb +0 -41
  117. data/lib/god/diagnostics.rb +0 -37
  118. data/test/test_dependency_graph.rb +0 -62
@@ -3,20 +3,20 @@ God.watch do |w|
3
3
  w.interval = 5.seconds
4
4
  w.start = File.join(GOD_ROOT, *%w[test configs child_events simple_server.rb])
5
5
  # w.log = File.join(GOD_ROOT, *%w[test configs child_events god.log])
6
-
6
+
7
7
  # determine the state on startup
8
8
  w.transition(:init, { true => :up, false => :start }) do |on|
9
9
  on.condition(:process_running) do |c|
10
10
  c.running = true
11
11
  end
12
12
  end
13
-
13
+
14
14
  # determine when process has finished starting
15
15
  w.transition([:start, :restart], :up) do |on|
16
16
  on.condition(:process_running) do |c|
17
17
  c.running = true
18
18
  end
19
-
19
+
20
20
  # failsafe
21
21
  on.condition(:tries) do |c|
22
22
  c.times = 2
@@ -28,7 +28,7 @@ God.watch do |w|
28
28
  w.transition(:up, :start) do |on|
29
29
  on.condition(:process_exits)
30
30
  end
31
-
31
+
32
32
  # lifecycle
33
33
  w.lifecycle do |on|
34
34
  on.condition(:flapping) do |c|
@@ -41,4 +41,4 @@ God.watch do |w|
41
41
  c.retry_within = 5.minutes
42
42
  end
43
43
  end
44
- end
44
+ end
@@ -1,3 +1,3 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
- loop { puts 'server'; sleep 1 }
3
+ loop { puts 'server'; sleep 1 }
@@ -3,25 +3,25 @@ God.watch do |w|
3
3
  w.start = File.join(GOD_ROOT, *%w[test configs child_polls simple_server.rb])
4
4
  w.interval = 5
5
5
  w.grace = 2
6
-
6
+
7
7
  w.start_if do |start|
8
8
  start.condition(:process_running) do |c|
9
9
  c.running = false
10
10
  end
11
11
  end
12
-
12
+
13
13
  w.restart_if do |restart|
14
14
  restart.condition(:cpu_usage) do |c|
15
15
  c.above = 30.percent
16
16
  c.times = [3, 5]
17
17
  end
18
-
18
+
19
19
  restart.condition(:memory_usage) do |c|
20
20
  c.above = 10.megabytes
21
21
  c.times = [3, 5]
22
22
  end
23
23
  end
24
-
24
+
25
25
  # lifecycle
26
26
  w.lifecycle do |on|
27
27
  on.condition(:flapping) do |c|
@@ -1,12 +1,12 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
3
  data = ''
4
-
4
+
5
5
  loop do
6
6
  STDOUT.puts('server');
7
7
  STDOUT.flush;
8
-
8
+
9
9
  100000.times { data << 'x' }
10
-
10
+
11
11
  sleep 10
12
- end
12
+ end
@@ -3,20 +3,20 @@ God.watch do |w|
3
3
  w.interval = 5.seconds
4
4
  w.start = File.join(GOD_ROOT, *%w[test configs complex simple_server.rb])
5
5
  # w.log = File.join(GOD_ROOT, *%w[test configs child_events god.log])
6
-
6
+
7
7
  # determine the state on startup
8
8
  w.transition(:init, { true => :up, false => :start }) do |on|
9
9
  on.condition(:process_running) do |c|
10
10
  c.running = true
11
11
  end
12
12
  end
13
-
13
+
14
14
  # determine when process has finished starting
15
15
  w.transition([:start, :restart], :up) do |on|
16
16
  on.condition(:process_running) do |c|
17
17
  c.running = true
18
18
  end
19
-
19
+
20
20
  # failsafe
21
21
  on.condition(:tries) do |c|
22
22
  c.times = 2
@@ -28,7 +28,7 @@ God.watch do |w|
28
28
  w.transition(:up, :start) do |on|
29
29
  on.condition(:process_exits)
30
30
  end
31
-
31
+
32
32
  # restart if process is misbehaving
33
33
  w.transition(:up, :restart) do |on|
34
34
  on.condition(:complex) do |cc|
@@ -36,14 +36,14 @@ God.watch do |w|
36
36
  c.above = 0.percent
37
37
  c.times = 1
38
38
  end
39
-
39
+
40
40
  cc.and(:memory_usage) do |c|
41
41
  c.above = 0.megabytes
42
42
  c.times = 3
43
43
  end
44
44
  end
45
45
  end
46
-
46
+
47
47
  # lifecycle
48
48
  w.lifecycle do |on|
49
49
  on.condition(:flapping) do |c|
@@ -56,4 +56,4 @@ God.watch do |w|
56
56
  c.retry_within = 5.minutes
57
57
  end
58
58
  end
59
- end
59
+ end
@@ -1,3 +1,3 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
- loop { puts 'server'; sleep 1 }
3
+ loop { puts 'server'; sleep 1 }
@@ -105,4 +105,4 @@ God.watch do |w|
105
105
  c.retry_within = 5.minutes
106
106
  end
107
107
  end
108
- end
108
+ end
@@ -1,3 +1,3 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
- loop { puts 'server'; sleep 1 }
3
+ loop { puts 'server'; sleep 1 }
@@ -7,22 +7,22 @@ God.watch do |w|
7
7
  w.log = File.join(File.dirname(__FILE__), 'daemon_events.log')
8
8
  w.uid = 'tom'
9
9
  w.gid = 'tom'
10
-
10
+
11
11
  w.behavior(:clean_pid_file)
12
-
12
+
13
13
  # determine the state on startup
14
14
  w.transition(:init, { true => :up, false => :start }) do |on|
15
15
  on.condition(:process_running) do |c|
16
16
  c.running = true
17
17
  end
18
18
  end
19
-
19
+
20
20
  # determine when process has finished starting
21
21
  w.transition([:start, :restart], :up) do |on|
22
22
  on.condition(:process_running) do |c|
23
23
  c.running = true
24
24
  end
25
-
25
+
26
26
  # failsafe
27
27
  on.condition(:tries) do |c|
28
28
  c.times = 2
@@ -34,4 +34,4 @@ God.watch do |w|
34
34
  w.transition(:up, :start) do |on|
35
35
  on.condition(:process_exits)
36
36
  end
37
- end
37
+ end
@@ -5,4 +5,4 @@ puts 'simple server ahoy!'
5
5
 
6
6
  Daemons.run_proc('daemon-events', {:dir_mode => :system}) do
7
7
  loop { puts 'server'; sleep 1 }
8
- end
8
+ end
@@ -8,4 +8,4 @@ end
8
8
  p ENV
9
9
 
10
10
  command = '/usr/local/bin/ruby ' + File.join(File.dirname(__FILE__), *%w[simple_server.rb]) + ' stop'
11
- system(command)
11
+ system(command)
@@ -6,12 +6,12 @@ God.watch do |w|
6
6
  w.pid_file = '/var/run/daemon-polls.pid'
7
7
  w.start_grace = 2.seconds
8
8
  w.log = File.join(File.dirname(__FILE__), *%w[out.log])
9
-
9
+
10
10
  w.behavior(:clean_pid_file)
11
-
11
+
12
12
  w.start_if do |start|
13
13
  start.condition(:process_running) do |c|
14
14
  c.running = false
15
15
  end
16
16
  end
17
- end
17
+ end
@@ -3,4 +3,4 @@ require 'daemons'
3
3
 
4
4
  Daemons.run_proc('daemon-polls', {:dir_mode => :system}) do
5
5
  loop { STDOUT.puts('server'); STDOUT.flush; sleep 1 }
6
- end
6
+ end
@@ -4,13 +4,13 @@ God.watch do |w|
4
4
  w.interval = 5
5
5
  w.grace = 2
6
6
  w.group = 'test'
7
-
7
+
8
8
  w.start_if do |start|
9
9
  start.condition(:process_running) do |c|
10
10
  c.running = false
11
11
  end
12
12
  end
13
-
13
+
14
14
  w.restart_if do |restart|
15
15
  restart.condition(:degrading_lambda) do |c|
16
16
  require 'socket'
@@ -28,4 +28,4 @@ God.watch do |w|
28
28
  }
29
29
  end
30
30
  end
31
- end
31
+ end
@@ -0,0 +1,9 @@
1
+ God.watch do |w|
2
+ w.name = 'keepalive'
3
+ w.start = File.join(GOD_ROOT, *%w[test configs keepalive keepalive.rb])
4
+ w.log = File.join(GOD_ROOT, *%w[test configs keepalive keepalive.log])
5
+
6
+ w.keepalive(:interval => 5.seconds,
7
+ :memory_max => 10.megabytes,
8
+ :cpu_max => 30.percent)
9
+ end
@@ -0,0 +1,12 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ data = ''
4
+
5
+ loop do
6
+ STDOUT.puts('server');
7
+ STDOUT.flush;
8
+
9
+ 100000.times { data << 'x' }
10
+
11
+ # sleep 10
12
+ end
@@ -14,7 +14,7 @@ God.watch do |w|
14
14
  w.name = "lifecycle"
15
15
  w.interval = 5.seconds
16
16
  w.start = "/dev/null"
17
-
17
+
18
18
  # lifecycle
19
19
  w.lifecycle do |on|
20
20
  on.condition(:always) do |c|
@@ -22,4 +22,4 @@ God.watch do |w|
22
22
  c.notify = "tom2"
23
23
  end
24
24
  end
25
- end
25
+ end
@@ -5,7 +5,7 @@ God.task do |w|
5
5
  w.interval = 5.seconds
6
6
  w.valid_states = [:init, :up, :down]
7
7
  w.initial_state = :init
8
-
8
+
9
9
  # determine the state on startup
10
10
  w.transition(:init, { true => :up, false => :down }) do |on|
11
11
  on.condition(:process_running) do |c|
@@ -13,7 +13,7 @@ God.task do |w|
13
13
  c.pid_file = $pid_file
14
14
  end
15
15
  end
16
-
16
+
17
17
  # when process is up
18
18
  w.transition(:up, :down) do |on|
19
19
  # transition to 'start' if process goes down
@@ -21,7 +21,7 @@ God.task do |w|
21
21
  c.running = false
22
22
  c.pid_file = $pid_file
23
23
  end
24
-
24
+
25
25
  # send up info
26
26
  on.condition(:lambda) do |c|
27
27
  c.lambda = lambda do
@@ -30,7 +30,7 @@ God.task do |w|
30
30
  end
31
31
  end
32
32
  end
33
-
33
+
34
34
  # when process is down
35
35
  w.transition(:down, :up) do |on|
36
36
  # transition to 'up' if process comes up
@@ -38,7 +38,7 @@ God.task do |w|
38
38
  c.running = true
39
39
  c.pid_file = $pid_file
40
40
  end
41
-
41
+
42
42
  # send down info
43
43
  on.condition(:lambda) do |c|
44
44
  c.lambda = lambda do
@@ -47,4 +47,4 @@ God.task do |w|
47
47
  end
48
48
  end
49
49
  end
50
- end
50
+ end
@@ -10,14 +10,14 @@ God.watch do |w|
10
10
  w.start = "mongrel_rails start -P ./log/mongrel.pid -c #{RAILS_ROOT} -d"
11
11
  w.stop = "mongrel_rails stop -P ./log/mongrel.pid -c #{RAILS_ROOT}"
12
12
  w.grace = 5
13
-
13
+
14
14
  pid_file = File.join(RAILS_ROOT, "log/mongrel.pid")
15
-
15
+
16
16
  # clean pid files before start if necessary
17
17
  w.behavior(:clean_pid_file) do |b|
18
18
  b.pid_file = pid_file
19
19
  end
20
-
20
+
21
21
  # start if process is not running
22
22
  w.start_if do |start|
23
23
  start.condition(:process_running) do |c|
@@ -25,7 +25,7 @@ God.watch do |w|
25
25
  c.pid_file = pid_file
26
26
  end
27
27
  end
28
-
28
+
29
29
  # restart if memory or cpu is too high
30
30
  w.restart_if do |restart|
31
31
  restart.condition(:memory_usage) do |c|
@@ -34,7 +34,7 @@ God.watch do |w|
34
34
  c.above = (50 * 1024) # 50mb
35
35
  c.times = [3, 5]
36
36
  end
37
-
37
+
38
38
  restart.condition(:cpu_usage) do |c|
39
39
  c.interval = 10
40
40
  c.pid_file = pid_file
@@ -52,8 +52,8 @@ end
52
52
  # File.mtime(f) < Time.now - (7 * 24 * 60 * 60)
53
53
  # end.each { |f| File.delete(f) }
54
54
  # end
55
- #
55
+ #
56
56
  # w.start_if do |start|
57
57
  # start.condition(:always)
58
58
  # end
59
- # end
59
+ # end
@@ -7,10 +7,10 @@ God.watch do |w|
7
7
  w.uid = 'tom'
8
8
  w.gid = 'tom'
9
9
  w.group = 'test'
10
-
10
+
11
11
  w.start_if do |start|
12
12
  start.condition(:process_running) do |c|
13
13
  c.running = false
14
14
  end
15
15
  end
16
- end
16
+ end
@@ -9,4 +9,4 @@ loop do
9
9
  STDOUT.flush;
10
10
 
11
11
  sleep 10
12
- end
12
+ end
@@ -1,3 +1,3 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
- loop { puts 'server'; sleep 1 }
3
+ loop { puts 'server'; sleep 1 }
@@ -5,11 +5,11 @@
5
5
  w.interval = 0
6
6
  w.grace = 2
7
7
  w.group = 'test'
8
-
8
+
9
9
  w.start_if do |start|
10
10
  start.condition(:process_running) do |c|
11
11
  c.running = false
12
12
  end
13
13
  end
14
14
  end
15
- end
15
+ end
@@ -5,17 +5,17 @@ God.task do |t|
5
5
  t.valid_states = [:ok, :clean]
6
6
  t.initial_state = :ok
7
7
  t.interval = 5
8
-
8
+
9
9
  # t.clean = lambda do
10
10
  # Dir[File.join(LOG_DIR, '*.log')].each do |f|
11
11
  # File.delete(f)
12
12
  # end
13
13
  # end
14
-
14
+
15
15
  t.clean = "rm #{File.join(LOG_DIR, '*.log')}"
16
-
16
+
17
17
  t.transition(:clean, :ok)
18
-
18
+
19
19
  t.transition(:ok, :clean) do |on|
20
20
  on.condition(:lambda) do |c|
21
21
  c.lambda = lambda do
@@ -23,4 +23,4 @@ God.task do |t|
23
23
  end
24
24
  end
25
25
  end
26
- end
26
+ end