god 0.11.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Announce.txt +6 -6
- data/Gemfile +2 -0
- data/History.txt +19 -2
- data/{README.txt → LICENSE} +0 -37
- data/README.md +31 -0
- data/Rakefile +80 -38
- data/bin/god +21 -21
- data/doc/god.asciidoc +1487 -0
- data/doc/intro.asciidoc +20 -0
- data/ext/god/extconf.rb +3 -3
- data/ext/god/kqueue_handler.c +18 -18
- data/ext/god/netlink_handler.c +31 -31
- data/god.gemspec +24 -16
- data/lib/god.rb +261 -204
- data/lib/god/behavior.rb +14 -14
- data/lib/god/behaviors/clean_pid_file.rb +5 -5
- data/lib/god/behaviors/clean_unix_socket.rb +10 -10
- data/lib/god/behaviors/notify_when_flapping.rb +12 -12
- data/lib/god/cli/command.rb +59 -46
- data/lib/god/cli/run.rb +33 -37
- data/lib/god/cli/version.rb +6 -6
- data/lib/god/compat19.rb +1 -4
- data/lib/god/condition.rb +21 -21
- data/lib/god/conditions/always.rb +19 -6
- data/lib/god/conditions/complex.rb +18 -18
- data/lib/god/conditions/cpu_usage.rb +14 -14
- data/lib/god/conditions/degrading_lambda.rb +8 -8
- data/lib/god/conditions/disk_usage.rb +5 -5
- data/lib/god/conditions/flapping.rb +23 -23
- data/lib/god/conditions/http_response_code.rb +35 -19
- data/lib/god/conditions/lambda.rb +2 -2
- data/lib/god/conditions/memory_usage.rb +13 -13
- data/lib/god/conditions/process_exits.rb +14 -20
- data/lib/god/conditions/process_running.rb +16 -25
- data/lib/god/conditions/socket_responding.rb +132 -0
- data/lib/god/conditions/tries.rb +10 -10
- data/lib/god/configurable.rb +10 -10
- data/lib/god/contact.rb +20 -20
- data/lib/god/contacts/email.rb +7 -4
- data/lib/god/contacts/jabber.rb +1 -1
- data/lib/god/driver.rb +96 -64
- data/lib/god/errors.rb +9 -9
- data/lib/god/event_handler.rb +19 -19
- data/lib/god/event_handlers/dummy_handler.rb +4 -4
- data/lib/god/event_handlers/kqueue_handler.rb +3 -3
- data/lib/god/event_handlers/netlink_handler.rb +2 -2
- data/lib/god/logger.rb +13 -13
- data/lib/god/metric.rb +50 -22
- data/lib/god/process.rb +53 -52
- data/lib/god/registry.rb +7 -7
- data/lib/god/simple_logger.rb +14 -14
- data/lib/god/socket.rb +11 -11
- data/lib/god/sugar.rb +30 -15
- data/lib/god/sys_logger.rb +2 -2
- data/lib/god/system/portable_poller.rb +8 -8
- data/lib/god/system/process.rb +8 -8
- data/lib/god/system/slash_proc_poller.rb +13 -13
- data/lib/god/task.rb +237 -188
- data/lib/god/timeline.rb +5 -5
- data/lib/god/trigger.rb +11 -11
- data/lib/god/watch.rb +205 -53
- data/test/configs/child_events/child_events.god +5 -5
- data/test/configs/child_events/simple_server.rb +1 -1
- data/test/configs/child_polls/child_polls.god +4 -4
- data/test/configs/child_polls/simple_server.rb +4 -4
- data/test/configs/complex/complex.god +7 -7
- data/test/configs/complex/simple_server.rb +1 -1
- data/test/configs/contact/contact.god +1 -1
- data/test/configs/contact/simple_server.rb +1 -1
- data/test/configs/daemon_events/daemon_events.god +5 -5
- data/test/configs/daemon_events/simple_server.rb +1 -1
- data/test/configs/daemon_events/simple_server_stop.rb +1 -1
- data/test/configs/daemon_polls/daemon_polls.god +3 -3
- data/test/configs/daemon_polls/simple_server.rb +1 -1
- data/test/configs/degrading_lambda/degrading_lambda.god +3 -3
- data/test/configs/keepalive/keepalive.god +9 -0
- data/test/configs/keepalive/keepalive.rb +12 -0
- data/test/configs/lifecycle/lifecycle.god +2 -2
- data/test/configs/matias/matias.god +6 -6
- data/test/configs/real.rb +7 -7
- data/test/configs/running_load/running_load.god +2 -2
- data/test/configs/stop_options/simple_server.rb +1 -1
- data/test/configs/stress/simple_server.rb +1 -1
- data/test/configs/stress/stress.god +2 -2
- data/test/configs/task/task.god +5 -5
- data/test/configs/test.rb +7 -7
- data/test/helper.rb +8 -8
- data/test/test_behavior.rb +3 -3
- data/test/test_campfire.rb +1 -2
- data/test/test_condition.rb +10 -10
- data/test/test_conditions_disk_usage.rb +12 -12
- data/test/test_conditions_http_response_code.rb +24 -24
- data/test/test_conditions_process_running.rb +7 -7
- data/test/test_conditions_socket_responding.rb +122 -0
- data/test/test_conditions_tries.rb +12 -12
- data/test/test_contact.rb +19 -19
- data/test/test_driver.rb +17 -3
- data/test/test_event_handler.rb +12 -12
- data/test/test_god.rb +195 -117
- data/test/test_handlers_kqueue_handler.rb +4 -4
- data/test/test_jabber.rb +1 -1
- data/test/test_logger.rb +17 -17
- data/test/test_metric.rb +16 -16
- data/test/test_process.rb +47 -41
- data/test/test_prowl.rb +1 -1
- data/test/test_registry.rb +2 -2
- data/test/test_socket.rb +3 -3
- data/test/test_sugar.rb +7 -7
- data/test/test_system_portable_poller.rb +1 -1
- data/test/test_system_process.rb +5 -5
- data/test/test_task.rb +57 -57
- data/test/test_timeline.rb +8 -8
- data/test/test_trigger.rb +16 -16
- data/test/test_watch.rb +69 -62
- metadata +182 -69
- data/lib/god/dependency_graph.rb +0 -41
- data/lib/god/diagnostics.rb +0 -37
- 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
|
@@ -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|
|
@@ -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
|
@@ -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
|
@@ -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
|
@@ -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
|
@@ -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
|
data/test/configs/real.rb
CHANGED
@@ -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
|
data/test/configs/task/task.god
CHANGED
@@ -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
|