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.
Files changed (138) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +559 -0
  3. data/README.md +9 -4
  4. data/bin/god +26 -28
  5. data/ext/god/extconf.rb +9 -9
  6. data/lib/god/behavior.rb +3 -5
  7. data/lib/god/behaviors/clean_pid_file.rb +4 -6
  8. data/lib/god/behaviors/clean_unix_socket.rb +4 -6
  9. data/lib/god/behaviors/notify_when_flapping.rb +13 -15
  10. data/lib/god/cli/command.rb +109 -89
  11. data/lib/god/cli/run.rb +51 -75
  12. data/lib/god/cli/version.rb +2 -4
  13. data/lib/god/condition.rb +12 -14
  14. data/lib/god/conditions/always.rb +3 -2
  15. data/lib/god/conditions/complex.rb +23 -24
  16. data/lib/god/conditions/cpu_usage.rb +12 -16
  17. data/lib/god/conditions/degrading_lambda.rb +15 -19
  18. data/lib/god/conditions/disk_usage.rb +7 -8
  19. data/lib/god/conditions/file_mtime.rb +3 -7
  20. data/lib/god/conditions/file_touched.rb +4 -5
  21. data/lib/god/conditions/flapping.rb +57 -62
  22. data/lib/god/conditions/http_response_code.rb +27 -32
  23. data/lib/god/conditions/lambda.rb +3 -5
  24. data/lib/god/conditions/memory_usage.rb +12 -16
  25. data/lib/god/conditions/process_exits.rb +12 -12
  26. data/lib/god/conditions/process_running.rb +8 -10
  27. data/lib/god/conditions/socket_responding.rb +23 -28
  28. data/lib/god/conditions/tries.rb +12 -14
  29. data/lib/god/configurable.rb +7 -10
  30. data/lib/god/contact.rb +41 -52
  31. data/lib/god/contacts/airbrake.rb +10 -12
  32. data/lib/god/contacts/campfire.rb +18 -20
  33. data/lib/god/contacts/email.rb +27 -28
  34. data/lib/god/contacts/prowl.rb +16 -17
  35. data/lib/god/contacts/scout.rb +2 -5
  36. data/lib/god/contacts/sensu.rb +15 -11
  37. data/lib/god/contacts/slack.rb +23 -33
  38. data/lib/god/contacts/statsd.rb +8 -8
  39. data/lib/god/contacts/twitter.rb +2 -2
  40. data/lib/god/contacts/webhook.rb +21 -24
  41. data/lib/god/driver.rb +12 -18
  42. data/lib/god/errors.rb +0 -2
  43. data/lib/god/event_handler.rb +40 -49
  44. data/lib/god/event_handlers/dummy_handler.rb +1 -1
  45. data/lib/god/event_handlers/kqueue_handler.rb +2 -2
  46. data/lib/god/event_handlers/netlink_handler.rb +1 -1
  47. data/lib/god/logger.rb +5 -13
  48. data/lib/god/metric.rb +13 -15
  49. data/lib/god/process.rb +93 -98
  50. data/lib/god/simple_logger.rb +13 -15
  51. data/lib/god/socket.rb +21 -23
  52. data/lib/god/sugar.rb +8 -8
  53. data/lib/god/sys_logger.rb +6 -8
  54. data/lib/god/system/portable_poller.rb +1 -9
  55. data/lib/god/system/process.rb +4 -6
  56. data/lib/god/system/slash_proc_poller.rb +17 -19
  57. data/lib/god/task.rb +110 -136
  58. data/lib/god/timeline.rb +2 -4
  59. data/lib/god/trigger.rb +7 -11
  60. data/lib/god/version.rb +1 -1
  61. data/lib/god/watch.rb +51 -57
  62. data/lib/god.rb +122 -148
  63. metadata +17 -370
  64. data/Announce.txt +0 -135
  65. data/Gemfile +0 -5
  66. data/Rakefile +0 -129
  67. data/doc/god.asciidoc +0 -1592
  68. data/doc/intro.asciidoc +0 -20
  69. data/ext/god/.gitignore +0 -5
  70. data/lib/god/compat19.rb +0 -33
  71. data/lib/god/contacts/hipchat.rb +0 -117
  72. data/lib/god/contacts/jabber.rb +0 -75
  73. data/test/configs/child_events/child_events.god +0 -44
  74. data/test/configs/child_events/simple_server.rb +0 -3
  75. data/test/configs/child_polls/child_polls.god +0 -37
  76. data/test/configs/child_polls/simple_server.rb +0 -12
  77. data/test/configs/complex/complex.god +0 -59
  78. data/test/configs/complex/simple_server.rb +0 -3
  79. data/test/configs/contact/contact.god +0 -118
  80. data/test/configs/contact/simple_server.rb +0 -3
  81. data/test/configs/daemon_events/daemon_events.god +0 -37
  82. data/test/configs/daemon_events/simple_server.rb +0 -8
  83. data/test/configs/daemon_events/simple_server_stop.rb +0 -11
  84. data/test/configs/daemon_polls/daemon_polls.god +0 -17
  85. data/test/configs/daemon_polls/simple_server.rb +0 -6
  86. data/test/configs/degrading_lambda/degrading_lambda.god +0 -31
  87. data/test/configs/degrading_lambda/tcp_server.rb +0 -15
  88. data/test/configs/keepalive/keepalive.god +0 -9
  89. data/test/configs/keepalive/keepalive.rb +0 -12
  90. data/test/configs/lifecycle/lifecycle.god +0 -25
  91. data/test/configs/matias/matias.god +0 -50
  92. data/test/configs/real.rb +0 -59
  93. data/test/configs/running_load/running_load.god +0 -16
  94. data/test/configs/stop_options/simple_server.rb +0 -12
  95. data/test/configs/stop_options/stop_options.god +0 -39
  96. data/test/configs/stress/simple_server.rb +0 -3
  97. data/test/configs/stress/stress.god +0 -15
  98. data/test/configs/task/logs/.placeholder +0 -0
  99. data/test/configs/task/task.god +0 -26
  100. data/test/configs/test.rb +0 -61
  101. data/test/configs/usr1_trapper.rb +0 -10
  102. data/test/helper.rb +0 -172
  103. data/test/suite.rb +0 -6
  104. data/test/test_airbrake.rb +0 -14
  105. data/test/test_behavior.rb +0 -18
  106. data/test/test_campfire.rb +0 -22
  107. data/test/test_condition.rb +0 -52
  108. data/test/test_conditions_disk_usage.rb +0 -50
  109. data/test/test_conditions_http_response_code.rb +0 -109
  110. data/test/test_conditions_process_running.rb +0 -40
  111. data/test/test_conditions_socket_responding.rb +0 -176
  112. data/test/test_conditions_tries.rb +0 -67
  113. data/test/test_contact.rb +0 -109
  114. data/test/test_driver.rb +0 -26
  115. data/test/test_email.rb +0 -34
  116. data/test/test_event_handler.rb +0 -82
  117. data/test/test_god.rb +0 -710
  118. data/test/test_god_system.rb +0 -201
  119. data/test/test_handlers_kqueue_handler.rb +0 -16
  120. data/test/test_hipchat.rb +0 -23
  121. data/test/test_jabber.rb +0 -29
  122. data/test/test_logger.rb +0 -55
  123. data/test/test_metric.rb +0 -74
  124. data/test/test_process.rb +0 -263
  125. data/test/test_prowl.rb +0 -15
  126. data/test/test_registry.rb +0 -15
  127. data/test/test_sensu.rb +0 -11
  128. data/test/test_slack.rb +0 -57
  129. data/test/test_socket.rb +0 -34
  130. data/test/test_statsd.rb +0 -22
  131. data/test/test_sugar.rb +0 -42
  132. data/test/test_system_portable_poller.rb +0 -17
  133. data/test/test_system_process.rb +0 -30
  134. data/test/test_task.rb +0 -246
  135. data/test/test_timeline.rb +0 -37
  136. data/test/test_trigger.rb +0 -63
  137. data/test/test_watch.rb +0 -286
  138. 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 Sybmol initial state.
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
- :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=
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
- self.behaviors << b
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 runn poll checks.
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 Numberic#percent
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
- self.transition(:init, { true => :up, false => :start }) do |on|
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
- self.transition([:start, :restart], :up) do |on|
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
- self.transition(:up, :start) do |on|
154
+ transition(:up, :start) do |on|
155
155
  on.condition(:process_exits)
156
156
  end
157
157
  else
158
- self.start_if do |start|
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
- self.restart_if do |restart|
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
- self.transition(:up, :start) do |on|
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
- self.transition(:up, :restart) do |on|
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
- self.transition(:up, :stop) do |on|
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 !self.metrics[:init].empty?
235
- self.move(:init)
228
+ if metrics[:init].empty?
229
+ move(:up)
236
230
  else
237
- self.move(:up)
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
- # a - The Symbol action to perform. One of :start, :restart, :stop.
250
- # c - The Condition.
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(a, c = nil)
254
- if !self.driver.in_driver_context?
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 a
250
+ case action
260
251
  when :start
261
- call_action(c, :start)
262
- sleep(self.start_grace + self.grace)
252
+ call_action(condition, :start)
253
+ sleep(start_grace + grace)
263
254
  when :restart
264
- if self.restart
265
- call_action(c, :restart)
255
+ if restart
256
+ call_action(condition, :restart)
266
257
  else
267
- action(:stop, c)
268
- action(:start, c)
258
+ action(:stop, condition)
259
+ action(:start, condition)
269
260
  end
270
- sleep(self.restart_grace + self.grace)
261
+ sleep(restart_grace + grace)
271
262
  when :stop
272
- call_action(c, :stop)
273
- sleep(self.stop_grace + self.grace)
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 = self.behaviors
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 = "#{self.name} before_#{action}: #{info} (#{b.base_name})"
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 self.send(action)
300
- msg = "#{self.name} #{action}: #{self.send(action).to_s}"
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 = self.behaviors
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 = "#{self.name} after_#{action}: #{info} (#{b.base_name})"
307
+ msg = "#{name} after_#{action}: #{info} (#{b.base_name})"
314
308
  applog(self, :info, msg)
315
309
  end
316
310
  end