resurrected_god 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Announce.txt +135 -0
- data/Gemfile +5 -0
- data/LICENSE +22 -0
- data/README.md +33 -0
- data/Rakefile +129 -0
- data/bin/god +134 -0
- data/doc/god.asciidoc +1592 -0
- data/doc/intro.asciidoc +20 -0
- data/ext/god/.gitignore +5 -0
- data/ext/god/extconf.rb +56 -0
- data/ext/god/kqueue_handler.c +133 -0
- data/ext/god/netlink_handler.c +182 -0
- data/lib/god/behavior.rb +52 -0
- data/lib/god/behaviors/clean_pid_file.rb +21 -0
- data/lib/god/behaviors/clean_unix_socket.rb +21 -0
- data/lib/god/behaviors/notify_when_flapping.rb +51 -0
- data/lib/god/cli/command.rb +268 -0
- data/lib/god/cli/run.rb +170 -0
- data/lib/god/cli/version.rb +23 -0
- data/lib/god/compat19.rb +33 -0
- data/lib/god/condition.rb +96 -0
- data/lib/god/conditions/always.rb +36 -0
- data/lib/god/conditions/complex.rb +86 -0
- data/lib/god/conditions/cpu_usage.rb +80 -0
- data/lib/god/conditions/degrading_lambda.rb +52 -0
- data/lib/god/conditions/disk_usage.rb +32 -0
- data/lib/god/conditions/file_mtime.rb +28 -0
- data/lib/god/conditions/file_touched.rb +44 -0
- data/lib/god/conditions/flapping.rb +128 -0
- data/lib/god/conditions/http_response_code.rb +184 -0
- data/lib/god/conditions/lambda.rb +25 -0
- data/lib/god/conditions/memory_usage.rb +82 -0
- data/lib/god/conditions/process_exits.rb +66 -0
- data/lib/god/conditions/process_running.rb +63 -0
- data/lib/god/conditions/socket_responding.rb +142 -0
- data/lib/god/conditions/tries.rb +44 -0
- data/lib/god/configurable.rb +57 -0
- data/lib/god/contact.rb +114 -0
- data/lib/god/contacts/airbrake.rb +44 -0
- data/lib/god/contacts/campfire.rb +121 -0
- data/lib/god/contacts/email.rb +130 -0
- data/lib/god/contacts/hipchat.rb +117 -0
- data/lib/god/contacts/jabber.rb +75 -0
- data/lib/god/contacts/prowl.rb +57 -0
- data/lib/god/contacts/scout.rb +55 -0
- data/lib/god/contacts/sensu.rb +59 -0
- data/lib/god/contacts/slack.rb +98 -0
- data/lib/god/contacts/statsd.rb +46 -0
- data/lib/god/contacts/twitter.rb +51 -0
- data/lib/god/contacts/webhook.rb +74 -0
- data/lib/god/driver.rb +238 -0
- data/lib/god/errors.rb +24 -0
- data/lib/god/event_handler.rb +112 -0
- data/lib/god/event_handlers/dummy_handler.rb +13 -0
- data/lib/god/event_handlers/kqueue_handler.rb +17 -0
- data/lib/god/event_handlers/netlink_handler.rb +13 -0
- data/lib/god/logger.rb +109 -0
- data/lib/god/metric.rb +87 -0
- data/lib/god/process.rb +381 -0
- data/lib/god/registry.rb +32 -0
- data/lib/god/simple_logger.rb +59 -0
- data/lib/god/socket.rb +113 -0
- data/lib/god/sugar.rb +62 -0
- data/lib/god/sys_logger.rb +45 -0
- data/lib/god/system/portable_poller.rb +42 -0
- data/lib/god/system/process.rb +50 -0
- data/lib/god/system/slash_proc_poller.rb +92 -0
- data/lib/god/task.rb +552 -0
- data/lib/god/timeline.rb +25 -0
- data/lib/god/trigger.rb +43 -0
- data/lib/god/version.rb +4 -0
- data/lib/god/watch.rb +340 -0
- data/lib/god.rb +777 -0
- data/test/configs/child_events/child_events.god +44 -0
- data/test/configs/child_events/simple_server.rb +3 -0
- data/test/configs/child_polls/child_polls.god +37 -0
- data/test/configs/child_polls/simple_server.rb +12 -0
- data/test/configs/complex/complex.god +59 -0
- data/test/configs/complex/simple_server.rb +3 -0
- data/test/configs/contact/contact.god +118 -0
- data/test/configs/contact/simple_server.rb +3 -0
- data/test/configs/daemon_events/daemon_events.god +37 -0
- data/test/configs/daemon_events/simple_server.rb +8 -0
- data/test/configs/daemon_events/simple_server_stop.rb +11 -0
- data/test/configs/daemon_polls/daemon_polls.god +17 -0
- data/test/configs/daemon_polls/simple_server.rb +6 -0
- data/test/configs/degrading_lambda/degrading_lambda.god +31 -0
- data/test/configs/degrading_lambda/tcp_server.rb +15 -0
- data/test/configs/keepalive/keepalive.god +9 -0
- data/test/configs/keepalive/keepalive.rb +12 -0
- data/test/configs/lifecycle/lifecycle.god +25 -0
- data/test/configs/matias/matias.god +50 -0
- data/test/configs/real.rb +59 -0
- data/test/configs/running_load/running_load.god +16 -0
- data/test/configs/stop_options/simple_server.rb +12 -0
- data/test/configs/stop_options/stop_options.god +39 -0
- data/test/configs/stress/simple_server.rb +3 -0
- data/test/configs/stress/stress.god +15 -0
- data/test/configs/task/logs/.placeholder +0 -0
- data/test/configs/task/task.god +26 -0
- data/test/configs/test.rb +61 -0
- data/test/configs/usr1_trapper.rb +10 -0
- data/test/helper.rb +172 -0
- data/test/suite.rb +6 -0
- data/test/test_airbrake.rb +14 -0
- data/test/test_behavior.rb +18 -0
- data/test/test_campfire.rb +22 -0
- data/test/test_condition.rb +52 -0
- data/test/test_conditions_disk_usage.rb +50 -0
- data/test/test_conditions_http_response_code.rb +109 -0
- data/test/test_conditions_process_running.rb +40 -0
- data/test/test_conditions_socket_responding.rb +176 -0
- data/test/test_conditions_tries.rb +67 -0
- data/test/test_contact.rb +109 -0
- data/test/test_driver.rb +26 -0
- data/test/test_email.rb +34 -0
- data/test/test_event_handler.rb +82 -0
- data/test/test_god.rb +710 -0
- data/test/test_god_system.rb +201 -0
- data/test/test_handlers_kqueue_handler.rb +16 -0
- data/test/test_hipchat.rb +23 -0
- data/test/test_jabber.rb +29 -0
- data/test/test_logger.rb +55 -0
- data/test/test_metric.rb +74 -0
- data/test/test_process.rb +263 -0
- data/test/test_prowl.rb +15 -0
- data/test/test_registry.rb +15 -0
- data/test/test_sensu.rb +11 -0
- data/test/test_slack.rb +57 -0
- data/test/test_socket.rb +34 -0
- data/test/test_statsd.rb +22 -0
- data/test/test_sugar.rb +42 -0
- data/test/test_system_portable_poller.rb +17 -0
- data/test/test_system_process.rb +30 -0
- data/test/test_task.rb +246 -0
- data/test/test_timeline.rb +37 -0
- data/test/test_trigger.rb +63 -0
- data/test/test_watch.rb +286 -0
- data/test/test_webhook.rb +22 -0
- metadata +476 -0
@@ -0,0 +1,44 @@
|
|
1
|
+
God.watch do |w|
|
2
|
+
w.name = "child-events"
|
3
|
+
w.interval = 5.seconds
|
4
|
+
w.start = File.join(GOD_ROOT, *%w[test configs child_events simple_server.rb])
|
5
|
+
# w.log = File.join(GOD_ROOT, *%w[test configs child_events god.log])
|
6
|
+
|
7
|
+
# determine the state on startup
|
8
|
+
w.transition(:init, { true => :up, false => :start }) do |on|
|
9
|
+
on.condition(:process_running) do |c|
|
10
|
+
c.running = true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# determine when process has finished starting
|
15
|
+
w.transition([:start, :restart], :up) do |on|
|
16
|
+
on.condition(:process_running) do |c|
|
17
|
+
c.running = true
|
18
|
+
end
|
19
|
+
|
20
|
+
# failsafe
|
21
|
+
on.condition(:tries) do |c|
|
22
|
+
c.times = 2
|
23
|
+
c.transition = :start
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# start if process is not running
|
28
|
+
w.transition(:up, :start) do |on|
|
29
|
+
on.condition(:process_exits)
|
30
|
+
end
|
31
|
+
|
32
|
+
# lifecycle
|
33
|
+
w.lifecycle do |on|
|
34
|
+
on.condition(:flapping) do |c|
|
35
|
+
c.to_state = [:start, :restart]
|
36
|
+
c.times = 5
|
37
|
+
c.within = 20.seconds
|
38
|
+
c.transition = :unmonitored
|
39
|
+
c.retry_in = 10.seconds
|
40
|
+
c.retry_times = 2
|
41
|
+
c.retry_within = 5.minutes
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
God.watch do |w|
|
2
|
+
w.name = 'child-polls'
|
3
|
+
w.start = File.join(GOD_ROOT, *%w[test configs child_polls simple_server.rb])
|
4
|
+
w.interval = 5
|
5
|
+
w.grace = 2
|
6
|
+
|
7
|
+
w.start_if do |start|
|
8
|
+
start.condition(:process_running) do |c|
|
9
|
+
c.running = false
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
w.restart_if do |restart|
|
14
|
+
restart.condition(:cpu_usage) do |c|
|
15
|
+
c.above = 30.percent
|
16
|
+
c.times = [3, 5]
|
17
|
+
end
|
18
|
+
|
19
|
+
restart.condition(:memory_usage) do |c|
|
20
|
+
c.above = 10.megabytes
|
21
|
+
c.times = [3, 5]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# lifecycle
|
26
|
+
w.lifecycle do |on|
|
27
|
+
on.condition(:flapping) do |c|
|
28
|
+
c.to_state = [:start, :restart]
|
29
|
+
c.times = 3
|
30
|
+
c.within = 60.seconds
|
31
|
+
c.transition = :unmonitored
|
32
|
+
c.retry_in = 10.seconds
|
33
|
+
c.retry_times = 2
|
34
|
+
c.retry_within = 5.minutes
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
God.watch do |w|
|
2
|
+
w.name = "complex"
|
3
|
+
w.interval = 5.seconds
|
4
|
+
w.start = File.join(GOD_ROOT, *%w[test configs complex simple_server.rb])
|
5
|
+
# w.log = File.join(GOD_ROOT, *%w[test configs child_events god.log])
|
6
|
+
|
7
|
+
# determine the state on startup
|
8
|
+
w.transition(:init, { true => :up, false => :start }) do |on|
|
9
|
+
on.condition(:process_running) do |c|
|
10
|
+
c.running = true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# determine when process has finished starting
|
15
|
+
w.transition([:start, :restart], :up) do |on|
|
16
|
+
on.condition(:process_running) do |c|
|
17
|
+
c.running = true
|
18
|
+
end
|
19
|
+
|
20
|
+
# failsafe
|
21
|
+
on.condition(:tries) do |c|
|
22
|
+
c.times = 2
|
23
|
+
c.transition = :start
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# start if process is not running
|
28
|
+
w.transition(:up, :start) do |on|
|
29
|
+
on.condition(:process_exits)
|
30
|
+
end
|
31
|
+
|
32
|
+
# restart if process is misbehaving
|
33
|
+
w.transition(:up, :restart) do |on|
|
34
|
+
on.condition(:complex) do |cc|
|
35
|
+
cc.and(:cpu_usage) do |c|
|
36
|
+
c.above = 0.percent
|
37
|
+
c.times = 1
|
38
|
+
end
|
39
|
+
|
40
|
+
cc.and(:memory_usage) do |c|
|
41
|
+
c.above = 0.megabytes
|
42
|
+
c.times = 3
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# lifecycle
|
48
|
+
w.lifecycle do |on|
|
49
|
+
on.condition(:flapping) do |c|
|
50
|
+
c.to_state = [:start, :restart]
|
51
|
+
c.times = 5
|
52
|
+
c.within = 20.seconds
|
53
|
+
c.transition = :unmonitored
|
54
|
+
c.retry_in = 10.seconds
|
55
|
+
c.retry_times = 2
|
56
|
+
c.retry_within = 5.minutes
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# God::Contacts::Campfire.defaults do |d|
|
2
|
+
# d.subdomain = 'github'
|
3
|
+
# d.token = '9fb768e421975cc1c6ff3f4f8306f890cb46e24f'
|
4
|
+
# d.room = 'Notices'
|
5
|
+
# d.ssl = true
|
6
|
+
# end
|
7
|
+
#
|
8
|
+
# God.contact(:campfire) do |c|
|
9
|
+
# c.name = 'tom4'
|
10
|
+
# end
|
11
|
+
|
12
|
+
# God::Contacts::Hipchat.defaults do |d|
|
13
|
+
# d.token = '9fb768e421975cc1c6ff3f4f8306f890cb46e24f'
|
14
|
+
# d.room = 'Notices'
|
15
|
+
# d.ssl = true
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# God.contact(:hipchat) do |c|
|
19
|
+
# c.name = 'hip1'
|
20
|
+
# end
|
21
|
+
|
22
|
+
# God.contact(:email) do |c|
|
23
|
+
# c.name = 'tom'
|
24
|
+
# c.group = 'developers'
|
25
|
+
# c.to_email = 'tom@lepton.local'
|
26
|
+
# c.from_email = 'god@github.com'
|
27
|
+
# c.from_name = 'God'
|
28
|
+
# c.delivery_method = :sendmail
|
29
|
+
# end
|
30
|
+
|
31
|
+
# God.contact(:email) do |c|
|
32
|
+
# c.name = 'tom'
|
33
|
+
# c.group = 'developers'
|
34
|
+
# c.to_email = 'tom@mojombo.com'
|
35
|
+
# c.from_email = 'god@github.com'
|
36
|
+
# c.from_name = 'God'
|
37
|
+
# c.server_host = 'smtp.rs.github.com'
|
38
|
+
# end
|
39
|
+
|
40
|
+
# God.contact(:prowl) do |c|
|
41
|
+
# c.name = 'tom3'
|
42
|
+
# c.apikey = 'f0fc8e1f3121672686337a631527eac2f1b6031c'
|
43
|
+
# c.group = 'developers'
|
44
|
+
# end
|
45
|
+
|
46
|
+
# God.contact(:twitter) do |c|
|
47
|
+
# c.name = 'tom6'
|
48
|
+
# c.consumer_token = 'gOhjax6s0L3mLeaTtBWPw'
|
49
|
+
# c.consumer_secret = 'yz4gpAVXJHKxvsGK85tEyzQJ7o2FEy27H1KEWL75jfA'
|
50
|
+
# c.access_token = '17376380-qS391nCrgaP4HKXAmZtM38gB56xUXMhx1NYbjT6mQ'
|
51
|
+
# c.access_secret = 'uMwCDeU4OXlEBWFQBc3KwGyY8OdWCtAV0Jg5KVB0'
|
52
|
+
# end
|
53
|
+
|
54
|
+
# God.contact(:scout) do |c|
|
55
|
+
# c.name = 'tom5'
|
56
|
+
# c.client_key = '583a51b5-acbc-2421-a830-b6f3f8e4b04e'
|
57
|
+
# c.plugin_id = '230641'
|
58
|
+
# end
|
59
|
+
|
60
|
+
# God.contact(:webhook) do |c|
|
61
|
+
# c.name = 'tom'
|
62
|
+
# c.url = "http://www.postbin.org/wk7guh"
|
63
|
+
# end
|
64
|
+
|
65
|
+
# God.contact(:jabber) do |c|
|
66
|
+
# c.name = 'tom'
|
67
|
+
# c.host = 'talk.google.com'
|
68
|
+
# c.to_jid = 'mojombo@jabber.org'
|
69
|
+
# c.from_jid = 'mojombo@gmail.com'
|
70
|
+
# c.password = 'secret'
|
71
|
+
# end
|
72
|
+
|
73
|
+
God.watch do |w|
|
74
|
+
w.name = "contact"
|
75
|
+
w.interval = 5.seconds
|
76
|
+
w.start = "ruby " + File.join(File.dirname(__FILE__), *%w[simple_server.rb])
|
77
|
+
w.log = "/Users/tom/contact.log"
|
78
|
+
|
79
|
+
# determine the state on startup
|
80
|
+
w.transition(:init, { true => :up, false => :start }) do |on|
|
81
|
+
on.condition(:process_running) do |c|
|
82
|
+
c.running = true
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# determine when process has finished starting
|
87
|
+
w.transition([:start, :restart], :up) do |on|
|
88
|
+
on.condition(:process_running) do |c|
|
89
|
+
c.running = true
|
90
|
+
end
|
91
|
+
|
92
|
+
# failsafe
|
93
|
+
on.condition(:tries) do |c|
|
94
|
+
c.times = 2
|
95
|
+
c.transition = :start
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# start if process is not running
|
100
|
+
w.transition(:up, :start) do |on|
|
101
|
+
on.condition(:process_exits) do |c|
|
102
|
+
c.notify = {:contacts => ['tom'], :priority => 1, :category => 'product'}
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# lifecycle
|
107
|
+
w.lifecycle do |on|
|
108
|
+
on.condition(:flapping) do |c|
|
109
|
+
c.to_state = [:start, :restart]
|
110
|
+
c.times = 5
|
111
|
+
c.within = 20.seconds
|
112
|
+
c.transition = :unmonitored
|
113
|
+
c.retry_in = 10.seconds
|
114
|
+
c.retry_times = 2
|
115
|
+
c.retry_within = 5.minutes
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
God.watch do |w|
|
2
|
+
w.name = "daemon-events"
|
3
|
+
w.interval = 5.seconds
|
4
|
+
w.start = 'ruby ' + File.join(File.dirname(__FILE__), *%w[simple_server.rb]) + ' start'
|
5
|
+
w.stop = 'ruby ' + File.join(File.dirname(__FILE__), *%w[simple_server_stop.rb])
|
6
|
+
w.pid_file = '/var/run/daemon-events.pid'
|
7
|
+
w.log = File.join(File.dirname(__FILE__), 'daemon_events.log')
|
8
|
+
w.uid = 'tom'
|
9
|
+
w.gid = 'tom'
|
10
|
+
|
11
|
+
w.behavior(:clean_pid_file)
|
12
|
+
|
13
|
+
# determine the state on startup
|
14
|
+
w.transition(:init, { true => :up, false => :start }) do |on|
|
15
|
+
on.condition(:process_running) do |c|
|
16
|
+
c.running = true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# determine when process has finished starting
|
21
|
+
w.transition([:start, :restart], :up) do |on|
|
22
|
+
on.condition(:process_running) do |c|
|
23
|
+
c.running = true
|
24
|
+
end
|
25
|
+
|
26
|
+
# failsafe
|
27
|
+
on.condition(:tries) do |c|
|
28
|
+
c.times = 2
|
29
|
+
c.transition = :start
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# start if process is not running
|
34
|
+
w.transition(:up, :start) do |on|
|
35
|
+
on.condition(:process_exits)
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
God.watch do |w|
|
2
|
+
w.name = "daemon-polls"
|
3
|
+
w.interval = 5.seconds
|
4
|
+
w.start = 'ruby ' + File.join(File.dirname(__FILE__), *%w[simple_server.rb]) + ' start'
|
5
|
+
w.stop = 'ruby ' + File.join(File.dirname(__FILE__), *%w[simple_server.rb]) + ' stop'
|
6
|
+
w.pid_file = '/var/run/daemon-polls.pid'
|
7
|
+
w.start_grace = 2.seconds
|
8
|
+
w.log = File.join(File.dirname(__FILE__), *%w[out.log])
|
9
|
+
|
10
|
+
w.behavior(:clean_pid_file)
|
11
|
+
|
12
|
+
w.start_if do |start|
|
13
|
+
start.condition(:process_running) do |c|
|
14
|
+
c.running = false
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
God.watch do |w|
|
2
|
+
w.name = 'degrading-lambda'
|
3
|
+
w.start = 'ruby ' + File.join(File.dirname(__FILE__), *%w[tcp_server.rb])
|
4
|
+
w.interval = 5
|
5
|
+
w.grace = 2
|
6
|
+
w.group = 'test'
|
7
|
+
|
8
|
+
w.start_if do |start|
|
9
|
+
start.condition(:process_running) do |c|
|
10
|
+
c.running = false
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
w.restart_if do |restart|
|
15
|
+
restart.condition(:degrading_lambda) do |c|
|
16
|
+
require 'socket'
|
17
|
+
c.lambda = lambda {
|
18
|
+
begin
|
19
|
+
sock = TCPSocket.open('127.0.0.1', 9090)
|
20
|
+
sock.send "2\n", 0
|
21
|
+
retval = sock.gets
|
22
|
+
puts "Retval is #{retval}"
|
23
|
+
sock.close
|
24
|
+
retval
|
25
|
+
rescue
|
26
|
+
false
|
27
|
+
end
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'socket'
|
4
|
+
server = TCPServer.new('127.0.0.1', 9090)
|
5
|
+
while (session = server.accept)
|
6
|
+
puts "Found a session"
|
7
|
+
request = session.gets
|
8
|
+
puts "Request: #{request}"
|
9
|
+
time = request.to_i
|
10
|
+
puts "Sleeping for #{time}"
|
11
|
+
sleep time
|
12
|
+
session.print "Slept for #{time} seconds"
|
13
|
+
session.close
|
14
|
+
puts "Session closed"
|
15
|
+
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,25 @@
|
|
1
|
+
God::Contacts::Twitter.settings = {
|
2
|
+
# this is for my 'mojombo2' twitter test account
|
3
|
+
# feel free to use it for testing your conditions
|
4
|
+
:username => 'mojombo@gmail.com',
|
5
|
+
:password => 'gok9we3ot1av2e'
|
6
|
+
}
|
7
|
+
|
8
|
+
God.contact(:twitter) do |c|
|
9
|
+
c.name = 'tom2'
|
10
|
+
c.group = 'developers'
|
11
|
+
end
|
12
|
+
|
13
|
+
God.watch do |w|
|
14
|
+
w.name = "lifecycle"
|
15
|
+
w.interval = 5.seconds
|
16
|
+
w.start = "/dev/null"
|
17
|
+
|
18
|
+
# lifecycle
|
19
|
+
w.lifecycle do |on|
|
20
|
+
on.condition(:always) do |c|
|
21
|
+
c.what = true
|
22
|
+
c.notify = "tom2"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
$pid_file = "/tmp/matias.pid"
|
2
|
+
|
3
|
+
God.task do |w|
|
4
|
+
w.name = "watcher"
|
5
|
+
w.interval = 5.seconds
|
6
|
+
w.valid_states = [:init, :up, :down]
|
7
|
+
w.initial_state = :init
|
8
|
+
|
9
|
+
# determine the state on startup
|
10
|
+
w.transition(:init, { true => :up, false => :down }) do |on|
|
11
|
+
on.condition(:process_running) do |c|
|
12
|
+
c.running = true
|
13
|
+
c.pid_file = $pid_file
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# when process is up
|
18
|
+
w.transition(:up, :down) do |on|
|
19
|
+
# transition to 'start' if process goes down
|
20
|
+
on.condition(:process_running) do |c|
|
21
|
+
c.running = false
|
22
|
+
c.pid_file = $pid_file
|
23
|
+
end
|
24
|
+
|
25
|
+
# send up info
|
26
|
+
on.condition(:lambda) do |c|
|
27
|
+
c.lambda = lambda do
|
28
|
+
puts 'yay I am up'
|
29
|
+
false
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# when process is down
|
35
|
+
w.transition(:down, :up) do |on|
|
36
|
+
# transition to 'up' if process comes up
|
37
|
+
on.condition(:process_running) do |c|
|
38
|
+
c.running = true
|
39
|
+
c.pid_file = $pid_file
|
40
|
+
end
|
41
|
+
|
42
|
+
# send down info
|
43
|
+
on.condition(:lambda) do |c|
|
44
|
+
c.lambda = lambda do
|
45
|
+
puts 'boo I am down'
|
46
|
+
false
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
if $0 == __FILE__
|
2
|
+
require File.join(File.dirname(__FILE__), *%w[.. .. lib god])
|
3
|
+
end
|
4
|
+
|
5
|
+
RAILS_ROOT = "/Users/tom/dev/git/helloworld"
|
6
|
+
|
7
|
+
God.watch do |w|
|
8
|
+
w.name = "local-3000"
|
9
|
+
w.interval = 5 # seconds
|
10
|
+
w.start = "mongrel_rails start -P ./log/mongrel.pid -c #{RAILS_ROOT} -d"
|
11
|
+
w.stop = "mongrel_rails stop -P ./log/mongrel.pid -c #{RAILS_ROOT}"
|
12
|
+
w.grace = 5
|
13
|
+
|
14
|
+
pid_file = File.join(RAILS_ROOT, "log/mongrel.pid")
|
15
|
+
|
16
|
+
# clean pid files before start if necessary
|
17
|
+
w.behavior(:clean_pid_file) do |b|
|
18
|
+
b.pid_file = pid_file
|
19
|
+
end
|
20
|
+
|
21
|
+
# start if process is not running
|
22
|
+
w.start_if do |start|
|
23
|
+
start.condition(:process_running) do |c|
|
24
|
+
c.running = false
|
25
|
+
c.pid_file = pid_file
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# restart if memory or cpu is too high
|
30
|
+
w.restart_if do |restart|
|
31
|
+
restart.condition(:memory_usage) do |c|
|
32
|
+
c.interval = 20
|
33
|
+
c.pid_file = pid_file
|
34
|
+
c.above = (50 * 1024) # 50mb
|
35
|
+
c.times = [3, 5]
|
36
|
+
end
|
37
|
+
|
38
|
+
restart.condition(:cpu_usage) do |c|
|
39
|
+
c.interval = 10
|
40
|
+
c.pid_file = pid_file
|
41
|
+
c.above = 10 # percent
|
42
|
+
c.times = [3, 5]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# clear old session files
|
48
|
+
# god.watch do |w|
|
49
|
+
# w.name = "local-session-cleanup"
|
50
|
+
# w.start = lambda do
|
51
|
+
# Dir["#{RAILS_ROOT}/tmp/sessions/ruby_sess.*"].select do |f|
|
52
|
+
# File.mtime(f) < Time.now - (7 * 24 * 60 * 60)
|
53
|
+
# end.each { |f| File.delete(f) }
|
54
|
+
# end
|
55
|
+
#
|
56
|
+
# w.start_if do |start|
|
57
|
+
# start.condition(:always)
|
58
|
+
# end
|
59
|
+
# end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
God.watch do |w|
|
2
|
+
w.name = 'running-load'
|
3
|
+
w.start = '/Users/tom/dev/god/test/configs/child_polls/simple_server.rb'
|
4
|
+
w.stop = ''
|
5
|
+
w.interval = 5
|
6
|
+
w.grace = 2
|
7
|
+
w.uid = 'tom'
|
8
|
+
w.gid = 'tom'
|
9
|
+
w.group = 'test'
|
10
|
+
|
11
|
+
w.start_if do |start|
|
12
|
+
start.condition(:process_running) do |c|
|
13
|
+
c.running = false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
God.watch do |w|
|
2
|
+
w.name = 'stop-options'
|
3
|
+
w.start = File.join(GOD_ROOT, *%w[test configs stop_options simple_server.rb])
|
4
|
+
w.stop_signal = 'USR1'
|
5
|
+
w.stop_timeout = 5
|
6
|
+
w.interval = 5
|
7
|
+
w.grace = 2
|
8
|
+
|
9
|
+
w.start_if do |start|
|
10
|
+
start.condition(:process_running) do |c|
|
11
|
+
c.running = false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
w.restart_if do |restart|
|
16
|
+
restart.condition(:cpu_usage) do |c|
|
17
|
+
c.above = 30.percent
|
18
|
+
c.times = [3, 5]
|
19
|
+
end
|
20
|
+
|
21
|
+
restart.condition(:memory_usage) do |c|
|
22
|
+
c.above = 10.megabytes
|
23
|
+
c.times = [3, 5]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# lifecycle
|
28
|
+
w.lifecycle do |on|
|
29
|
+
on.condition(:flapping) do |c|
|
30
|
+
c.to_state = [:start, :restart]
|
31
|
+
c.times = 3
|
32
|
+
c.within = 60.seconds
|
33
|
+
c.transition = :unmonitored
|
34
|
+
c.retry_in = 10.seconds
|
35
|
+
c.retry_times = 2
|
36
|
+
c.retry_within = 5.minutes
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
('01'..'08').each do |i|
|
2
|
+
God.watch do |w|
|
3
|
+
w.name = "stress-#{i}"
|
4
|
+
w.start = "ruby " + File.join(File.dirname(__FILE__), *%w[simple_server.rb])
|
5
|
+
w.interval = 0
|
6
|
+
w.grace = 2
|
7
|
+
w.group = 'test'
|
8
|
+
|
9
|
+
w.start_if do |start|
|
10
|
+
start.condition(:process_running) do |c|
|
11
|
+
c.running = false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
File without changes
|