resurrected_god 0.14.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +559 -0
- data/README.md +9 -4
- data/bin/god +26 -28
- data/ext/god/extconf.rb +9 -9
- data/lib/god/behavior.rb +3 -5
- data/lib/god/behaviors/clean_pid_file.rb +4 -6
- data/lib/god/behaviors/clean_unix_socket.rb +4 -6
- data/lib/god/behaviors/notify_when_flapping.rb +13 -15
- data/lib/god/cli/command.rb +109 -89
- data/lib/god/cli/run.rb +51 -75
- data/lib/god/cli/version.rb +2 -4
- data/lib/god/condition.rb +12 -14
- data/lib/god/conditions/always.rb +3 -2
- data/lib/god/conditions/complex.rb +23 -24
- data/lib/god/conditions/cpu_usage.rb +12 -16
- data/lib/god/conditions/degrading_lambda.rb +15 -19
- data/lib/god/conditions/disk_usage.rb +7 -8
- data/lib/god/conditions/file_mtime.rb +3 -7
- data/lib/god/conditions/file_touched.rb +4 -5
- data/lib/god/conditions/flapping.rb +57 -62
- data/lib/god/conditions/http_response_code.rb +27 -32
- data/lib/god/conditions/lambda.rb +3 -5
- data/lib/god/conditions/memory_usage.rb +12 -16
- data/lib/god/conditions/process_exits.rb +12 -12
- data/lib/god/conditions/process_running.rb +8 -10
- data/lib/god/conditions/socket_responding.rb +23 -28
- data/lib/god/conditions/tries.rb +12 -14
- data/lib/god/configurable.rb +7 -10
- data/lib/god/contact.rb +41 -52
- data/lib/god/contacts/airbrake.rb +10 -12
- data/lib/god/contacts/campfire.rb +18 -20
- data/lib/god/contacts/email.rb +27 -28
- data/lib/god/contacts/prowl.rb +16 -17
- data/lib/god/contacts/scout.rb +2 -5
- data/lib/god/contacts/sensu.rb +15 -11
- data/lib/god/contacts/slack.rb +23 -33
- data/lib/god/contacts/statsd.rb +8 -8
- data/lib/god/contacts/twitter.rb +2 -2
- data/lib/god/contacts/webhook.rb +21 -24
- data/lib/god/driver.rb +12 -18
- data/lib/god/errors.rb +0 -2
- data/lib/god/event_handler.rb +40 -49
- data/lib/god/event_handlers/dummy_handler.rb +1 -1
- data/lib/god/event_handlers/kqueue_handler.rb +2 -2
- data/lib/god/event_handlers/netlink_handler.rb +1 -1
- data/lib/god/logger.rb +5 -13
- data/lib/god/metric.rb +13 -15
- data/lib/god/process.rb +93 -98
- data/lib/god/simple_logger.rb +13 -15
- data/lib/god/socket.rb +21 -23
- data/lib/god/sugar.rb +8 -8
- data/lib/god/sys_logger.rb +6 -8
- data/lib/god/system/portable_poller.rb +1 -9
- data/lib/god/system/process.rb +4 -6
- data/lib/god/system/slash_proc_poller.rb +17 -19
- data/lib/god/task.rb +110 -136
- data/lib/god/timeline.rb +2 -4
- data/lib/god/trigger.rb +7 -11
- data/lib/god/version.rb +1 -1
- data/lib/god/watch.rb +51 -57
- data/lib/god.rb +122 -148
- metadata +17 -370
- data/Announce.txt +0 -135
- data/Gemfile +0 -5
- data/Rakefile +0 -129
- data/doc/god.asciidoc +0 -1592
- data/doc/intro.asciidoc +0 -20
- data/ext/god/.gitignore +0 -5
- data/lib/god/compat19.rb +0 -33
- data/lib/god/contacts/hipchat.rb +0 -117
- data/lib/god/contacts/jabber.rb +0 -75
- data/test/configs/child_events/child_events.god +0 -44
- data/test/configs/child_events/simple_server.rb +0 -3
- data/test/configs/child_polls/child_polls.god +0 -37
- data/test/configs/child_polls/simple_server.rb +0 -12
- data/test/configs/complex/complex.god +0 -59
- data/test/configs/complex/simple_server.rb +0 -3
- data/test/configs/contact/contact.god +0 -118
- data/test/configs/contact/simple_server.rb +0 -3
- data/test/configs/daemon_events/daemon_events.god +0 -37
- data/test/configs/daemon_events/simple_server.rb +0 -8
- data/test/configs/daemon_events/simple_server_stop.rb +0 -11
- data/test/configs/daemon_polls/daemon_polls.god +0 -17
- data/test/configs/daemon_polls/simple_server.rb +0 -6
- data/test/configs/degrading_lambda/degrading_lambda.god +0 -31
- data/test/configs/degrading_lambda/tcp_server.rb +0 -15
- data/test/configs/keepalive/keepalive.god +0 -9
- data/test/configs/keepalive/keepalive.rb +0 -12
- data/test/configs/lifecycle/lifecycle.god +0 -25
- data/test/configs/matias/matias.god +0 -50
- data/test/configs/real.rb +0 -59
- data/test/configs/running_load/running_load.god +0 -16
- data/test/configs/stop_options/simple_server.rb +0 -12
- data/test/configs/stop_options/stop_options.god +0 -39
- data/test/configs/stress/simple_server.rb +0 -3
- data/test/configs/stress/stress.god +0 -15
- data/test/configs/task/logs/.placeholder +0 -0
- data/test/configs/task/task.god +0 -26
- data/test/configs/test.rb +0 -61
- data/test/configs/usr1_trapper.rb +0 -10
- data/test/helper.rb +0 -172
- data/test/suite.rb +0 -6
- data/test/test_airbrake.rb +0 -14
- data/test/test_behavior.rb +0 -18
- data/test/test_campfire.rb +0 -22
- data/test/test_condition.rb +0 -52
- data/test/test_conditions_disk_usage.rb +0 -50
- data/test/test_conditions_http_response_code.rb +0 -109
- data/test/test_conditions_process_running.rb +0 -40
- data/test/test_conditions_socket_responding.rb +0 -176
- data/test/test_conditions_tries.rb +0 -67
- data/test/test_contact.rb +0 -109
- data/test/test_driver.rb +0 -26
- data/test/test_email.rb +0 -34
- data/test/test_event_handler.rb +0 -82
- data/test/test_god.rb +0 -710
- data/test/test_god_system.rb +0 -201
- data/test/test_handlers_kqueue_handler.rb +0 -16
- data/test/test_hipchat.rb +0 -23
- data/test/test_jabber.rb +0 -29
- data/test/test_logger.rb +0 -55
- data/test/test_metric.rb +0 -74
- data/test/test_process.rb +0 -263
- data/test/test_prowl.rb +0 -15
- data/test/test_registry.rb +0 -15
- data/test/test_sensu.rb +0 -11
- data/test/test_slack.rb +0 -57
- data/test/test_socket.rb +0 -34
- data/test/test_statsd.rb +0 -22
- data/test/test_sugar.rb +0 -42
- data/test/test_system_portable_poller.rb +0 -17
- data/test/test_system_process.rb +0 -30
- data/test/test_task.rb +0 -246
- data/test/test_timeline.rb +0 -37
- data/test/test_trigger.rb +0 -63
- data/test/test_watch.rb +0 -286
- data/test/test_webhook.rb +0 -22
data/lib/god/watch.rb
CHANGED
@@ -6,9 +6,9 @@ module God
|
|
6
6
|
# workflows. It has four states: init, up, start, and restart.
|
7
7
|
class Watch < Task
|
8
8
|
# The Array of Symbol valid task states.
|
9
|
-
VALID_STATES = [:init, :up, :start, :restart]
|
9
|
+
VALID_STATES = [:init, :up, :start, :restart].freeze
|
10
10
|
|
11
|
-
# The
|
11
|
+
# The Symbol initial state.
|
12
12
|
INITIAL_STATE = :init
|
13
13
|
|
14
14
|
# Public: The grace period for this process (seconds).
|
@@ -26,13 +26,13 @@ module God
|
|
26
26
|
# Public: God::Process delegators. See lib/god/process.rb for docs.
|
27
27
|
extend Forwardable
|
28
28
|
def_delegators :@process, :name, :uid, :gid, :start, :stop, :restart, :dir,
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
29
|
+
:name=, :uid=, :gid=, :start=, :stop=, :restart=,
|
30
|
+
:dir=, :pid_file, :pid_file=, :log, :log=,
|
31
|
+
:log_cmd, :log_cmd=, :err_log, :err_log=,
|
32
|
+
:err_log_cmd, :err_log_cmd=, :alive?, :pid,
|
33
|
+
:unix_socket, :unix_socket=, :chroot, :chroot=,
|
34
|
+
:env, :env=, :signal, :stop_timeout=,
|
35
|
+
:stop_signal=, :umask, :umask=
|
36
36
|
|
37
37
|
# Initialize a new Watch instance.
|
38
38
|
def initialize
|
@@ -84,7 +84,7 @@ module God
|
|
84
84
|
# out its own error messages by now.
|
85
85
|
abort unless b.valid?
|
86
86
|
|
87
|
-
|
87
|
+
behaviors << b
|
88
88
|
end
|
89
89
|
|
90
90
|
###########################################################################
|
@@ -93,16 +93,16 @@ module God
|
|
93
93
|
#
|
94
94
|
###########################################################################
|
95
95
|
|
96
|
-
# Default Integer interval at which keepalive will
|
96
|
+
# Default Integer interval at which keepalive will run poll checks.
|
97
97
|
DEFAULT_KEEPALIVE_INTERVAL = 5.seconds
|
98
98
|
|
99
99
|
# Default Integer or Array of Integers specification of how many times the
|
100
100
|
# memory condition must fail before triggering.
|
101
|
-
DEFAULT_KEEPALIVE_MEMORY_TIMES = [3, 5]
|
101
|
+
DEFAULT_KEEPALIVE_MEMORY_TIMES = [3, 5].freeze
|
102
102
|
|
103
103
|
# Default Integer or Array of Integers specification of how many times the
|
104
104
|
# CPU condition must fail before triggering.
|
105
|
-
DEFAULT_KEEPALIVE_CPU_TIMES = [3, 5]
|
105
|
+
DEFAULT_KEEPALIVE_CPU_TIMES = [3, 5].freeze
|
106
106
|
|
107
107
|
# Public: A set of conditions for easily getting started with simple watch
|
108
108
|
# scenarios. Keepalive is intended for use by beginners or on processes
|
@@ -127,7 +127,7 @@ module God
|
|
127
127
|
# 3 (three times), [3, 5] (three out of any five
|
128
128
|
# checks). Default: [3, 5].
|
129
129
|
# :cpu_max - The Integer CPU percentage max. Range is
|
130
|
-
# 0 to 100. You may use the
|
130
|
+
# 0 to 100. You may use the Numeric#percent
|
131
131
|
# sugar to clarify e.g. 50.percent.
|
132
132
|
# :cpu_times - If :cpu_max is set, :cpu_times can be
|
133
133
|
# set to either an Integer or a 2 element
|
@@ -137,25 +137,25 @@ module God
|
|
137
137
|
# checks). Default: [3, 5].
|
138
138
|
def keepalive(options = {})
|
139
139
|
if God::EventHandler.loaded?
|
140
|
-
|
140
|
+
transition(:init, { true => :up, false => :start }) do |on|
|
141
141
|
on.condition(:process_running) do |c|
|
142
142
|
c.interval = options[:interval] || DEFAULT_KEEPALIVE_INTERVAL
|
143
143
|
c.running = true
|
144
144
|
end
|
145
145
|
end
|
146
146
|
|
147
|
-
|
147
|
+
transition([:start, :restart], :up) do |on|
|
148
148
|
on.condition(:process_running) do |c|
|
149
149
|
c.interval = options[:interval] || DEFAULT_KEEPALIVE_INTERVAL
|
150
150
|
c.running = true
|
151
151
|
end
|
152
152
|
end
|
153
153
|
|
154
|
-
|
154
|
+
transition(:up, :start) do |on|
|
155
155
|
on.condition(:process_exits)
|
156
156
|
end
|
157
157
|
else
|
158
|
-
|
158
|
+
start_if do |start|
|
159
159
|
start.condition(:process_running) do |c|
|
160
160
|
c.interval = options[:interval] || DEFAULT_KEEPALIVE_INTERVAL
|
161
161
|
c.running = false
|
@@ -163,7 +163,7 @@ module God
|
|
163
163
|
end
|
164
164
|
end
|
165
165
|
|
166
|
-
|
166
|
+
restart_if do |restart|
|
167
167
|
if options[:memory_max]
|
168
168
|
restart.condition(:memory_usage) do |c|
|
169
169
|
c.interval = options[:interval] || DEFAULT_KEEPALIVE_INTERVAL
|
@@ -193,10 +193,8 @@ module God
|
|
193
193
|
# Yields the Metric upon which conditions can be added.
|
194
194
|
#
|
195
195
|
# Returns nothing.
|
196
|
-
def start_if
|
197
|
-
|
198
|
-
yield(on)
|
199
|
-
end
|
196
|
+
def start_if(&block)
|
197
|
+
transition(:up, :start, &block)
|
200
198
|
end
|
201
199
|
|
202
200
|
# Public: Restart the process if any of the given conditions are triggered.
|
@@ -204,10 +202,8 @@ module God
|
|
204
202
|
# Yields the Metric upon which conditions can be added.
|
205
203
|
#
|
206
204
|
# Returns nothing.
|
207
|
-
def restart_if
|
208
|
-
|
209
|
-
yield(on)
|
210
|
-
end
|
205
|
+
def restart_if(&block)
|
206
|
+
transition(:up, :restart, &block)
|
211
207
|
end
|
212
208
|
|
213
209
|
# Public: Stop the process if any of the given conditions are triggered.
|
@@ -215,10 +211,8 @@ module God
|
|
215
211
|
# Yields the Metric upon which conditions can be added.
|
216
212
|
#
|
217
213
|
# Returns nothing.
|
218
|
-
def stop_if
|
219
|
-
|
220
|
-
yield(on)
|
221
|
-
end
|
214
|
+
def stop_if(&block)
|
215
|
+
transition(:up, :stop, &block)
|
222
216
|
end
|
223
217
|
|
224
218
|
###########################################################################
|
@@ -231,10 +225,10 @@ module God
|
|
231
225
|
#
|
232
226
|
# Returns nothing.
|
233
227
|
def monitor
|
234
|
-
if
|
235
|
-
|
228
|
+
if metrics[:init].empty?
|
229
|
+
move(:up)
|
236
230
|
else
|
237
|
-
|
231
|
+
move(:init)
|
238
232
|
end
|
239
233
|
end
|
240
234
|
|
@@ -246,32 +240,32 @@ module God
|
|
246
240
|
|
247
241
|
# Perform an action.
|
248
242
|
#
|
249
|
-
#
|
250
|
-
#
|
243
|
+
# action - The Symbol action to perform. One of :start, :restart, :stop.
|
244
|
+
# condition - The Condition.
|
251
245
|
#
|
252
246
|
# Returns this Watch.
|
253
|
-
def action(
|
254
|
-
if
|
255
|
-
# Called from outside Driver. Send an async message to Driver.
|
256
|
-
self.driver.message(:action, [a, c])
|
257
|
-
else
|
247
|
+
def action(action, condition = nil)
|
248
|
+
if driver.in_driver_context?
|
258
249
|
# Called from within Driver.
|
259
|
-
case
|
250
|
+
case action
|
260
251
|
when :start
|
261
|
-
call_action(
|
262
|
-
sleep(
|
252
|
+
call_action(condition, :start)
|
253
|
+
sleep(start_grace + grace)
|
263
254
|
when :restart
|
264
|
-
if
|
265
|
-
call_action(
|
255
|
+
if restart
|
256
|
+
call_action(condition, :restart)
|
266
257
|
else
|
267
|
-
action(:stop,
|
268
|
-
action(:start,
|
258
|
+
action(:stop, condition)
|
259
|
+
action(:start, condition)
|
269
260
|
end
|
270
|
-
sleep(
|
261
|
+
sleep(restart_grace + grace)
|
271
262
|
when :stop
|
272
|
-
call_action(
|
273
|
-
sleep(
|
263
|
+
call_action(condition, :stop)
|
264
|
+
sleep(stop_grace + grace)
|
274
265
|
end
|
266
|
+
else
|
267
|
+
# Called from outside Driver. Send an async message to Driver.
|
268
|
+
driver.message(:action, [action, condition])
|
275
269
|
end
|
276
270
|
|
277
271
|
self
|
@@ -285,19 +279,19 @@ module God
|
|
285
279
|
# Returns nothing.
|
286
280
|
def call_action(condition, action)
|
287
281
|
# Before.
|
288
|
-
before_items =
|
282
|
+
before_items = behaviors
|
289
283
|
before_items += [condition] if condition
|
290
284
|
before_items.each do |b|
|
291
285
|
info = b.send("before_#{action}")
|
292
286
|
if info
|
293
|
-
msg = "#{
|
287
|
+
msg = "#{name} before_#{action}: #{info} (#{b.base_name})"
|
294
288
|
applog(self, :info, msg)
|
295
289
|
end
|
296
290
|
end
|
297
291
|
|
298
292
|
# Log.
|
299
|
-
if
|
300
|
-
msg = "#{
|
293
|
+
if send(action)
|
294
|
+
msg = "#{name} #{action}: #{send(action)}"
|
301
295
|
applog(self, :info, msg)
|
302
296
|
end
|
303
297
|
|
@@ -305,12 +299,12 @@ module God
|
|
305
299
|
@process.call_action(action)
|
306
300
|
|
307
301
|
# After.
|
308
|
-
after_items =
|
302
|
+
after_items = behaviors
|
309
303
|
after_items += [condition] if condition
|
310
304
|
after_items.each do |b|
|
311
305
|
info = b.send("after_#{action}")
|
312
306
|
if info
|
313
|
-
msg = "#{
|
307
|
+
msg = "#{name} after_#{action}: #{info} (#{b.base_name})"
|
314
308
|
applog(self, :info, msg)
|
315
309
|
end
|
316
310
|
end
|