bluepill 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +835 -0
  3. data/CONTRIBUTING.md +31 -0
  4. data/LICENSE +1 -1
  5. data/README.md +66 -29
  6. data/bin/bluepill +1 -1
  7. data/bluepill.gemspec +17 -6
  8. data/lib/bluepill/application.rb +321 -46
  9. data/lib/bluepill/condition_watch.rb +103 -8
  10. data/lib/bluepill/controller.rb +124 -13
  11. data/lib/bluepill/dsl/app_proxy.rb +102 -3
  12. data/lib/bluepill/dsl/process_factory.rb +183 -60
  13. data/lib/bluepill/dsl/process_proxy.rb +132 -14
  14. data/lib/bluepill/dsl.rb +27 -5
  15. data/lib/bluepill/group.rb +142 -9
  16. data/lib/bluepill/logger.rb +122 -5
  17. data/lib/bluepill/process.rb +575 -201
  18. data/lib/bluepill/process_commands.rb +264 -0
  19. data/lib/bluepill/process_conditions/always_true.rb +18 -4
  20. data/lib/bluepill/process_conditions/cpu_usage.rb +34 -0
  21. data/lib/bluepill/process_conditions/file_time.rb +40 -4
  22. data/lib/bluepill/process_conditions/http.rb +81 -23
  23. data/lib/bluepill/process_conditions/mem_usage.rb +61 -2
  24. data/lib/bluepill/process_conditions/process_condition.rb +43 -0
  25. data/lib/bluepill/process_conditions/running_time.rb +36 -1
  26. data/lib/bluepill/process_conditions/zombie_process.rb +26 -5
  27. data/lib/bluepill/process_conditions.rb +15 -1
  28. data/lib/bluepill/process_journal.rb +374 -114
  29. data/lib/bluepill/process_statistics.rb +33 -3
  30. data/lib/bluepill/socket.rb +63 -16
  31. data/lib/bluepill/system/commands.rb +286 -0
  32. data/lib/bluepill/system.rb +223 -228
  33. data/lib/bluepill/trigger.rb +110 -14
  34. data/lib/bluepill/triggers/flapping.rb +84 -3
  35. data/lib/bluepill/util/rotational_array.rb +24 -1
  36. data/lib/bluepill/version.rb +71 -19
  37. data/lib/bluepill.rb +25 -2
  38. data/sig/bluepill.rbs +941 -0
  39. data/sig/manifest.yaml +7 -0
  40. metadata +16 -34
  41. data/bin/sample_forking_server +0 -66
  42. data/lib/bluepill/application/client.rb +0 -6
  43. data/lib/bluepill/application/server.rb +0 -21
@@ -1,14 +1,49 @@
1
1
  module Bluepill
2
2
  module ProcessConditions
3
+ # Checks how long a process has been running, in seconds
4
+ #
5
+ # A config names it `checks :running_time`, with below: the longest the
6
+ # process may run (24.hours, say), to restart a process that has run for
7
+ # too long.
8
+ #
9
+ # @example
10
+ # process.checks :running_time, every: 10.minutes, below: 24.hours
11
+ #
12
+ # @api private
3
13
  class RunningTime < ProcessCondition
14
+ # Create the check
15
+ #
16
+ # @param [Hash{Symbol => Object}] options the check's options, with
17
+ # :below, the longest the process may run, in seconds
18
+ #
19
+ # @return [void]
20
+ #
21
+ # @api private
4
22
  def initialize(options = {})
23
+ super
5
24
  @below = options[:below]
6
25
  end
7
26
 
27
+ # Read how long the process has run from the tick's ps table
28
+ #
29
+ # @param [Integer, nil] pid the process's pid
30
+ # @param [Boolean] _include_children whether to include its children
31
+ #
32
+ # @return [Integer] the seconds since it started
33
+ #
34
+ # @api private
8
35
  def run(pid, _include_children)
9
- System.running_time(pid)
36
+ # Like the other ps conditions, a process missing from ps reads as 0
37
+ System.running_time(pid).to_i
10
38
  end
11
39
 
40
+ # Return whether the process has run for less than the limit
41
+ #
42
+ # @param [Integer] value the seconds run read
43
+ #
44
+ # @return [Boolean] true when it's below the limit
45
+ #
46
+ # @api private
12
47
  def check(value)
13
48
  value < @below
14
49
  end
@@ -1,17 +1,38 @@
1
1
  module Bluepill
2
2
  module ProcessConditions
3
- # Process must have cache_actual_pid set to false to function correctly:
3
+ # Checks whether a process is a zombie, which ps shows as <defunct>
4
4
  #
5
- # process.checks :zombie_process, every: 5.seconds
6
- # process.cache_actual_pid = false
7
-
5
+ # A config names it `checks :zombie_process`. The process must have
6
+ # cache_actual_pid set to false for it to work correctly.
7
+ #
8
+ # @example
9
+ # process.checks :zombie_process, every: 5.seconds
10
+ # process.cache_actual_pid = false
11
+ #
12
+ # @api private
8
13
  class ZombieProcess < ProcessCondition
14
+ # Read the process's command line from the tick's ps table
15
+ #
16
+ # @param [Integer, nil] pid the process's pid
17
+ # @param [Boolean] _include_children whether to include its children
18
+ #
19
+ # @return [String, nil] the command line, or nil for a process ps
20
+ # doesn't list
21
+ #
22
+ # @api private
9
23
  def run(pid, _include_children)
10
24
  System.command(pid)
11
25
  end
12
26
 
27
+ # Return whether the process isn't a zombie
28
+ #
29
+ # @param [String, nil] value the command line run read
30
+ #
31
+ # @return [Boolean] true unless the command line says <defunct>
32
+ #
33
+ # @api private
13
34
  def check(value)
14
- (value =~ /\<defunct\>/).nil?
35
+ (value =~ /<defunct>/).nil?
15
36
  end
16
37
  end
17
38
  end
@@ -1,5 +1,19 @@
1
1
  module Bluepill
2
+ # The checks a process can run, named in a config by their underscored
3
+ # class name, such as `checks :mem_usage`
4
+ #
5
+ # @api private
2
6
  module ProcessConditions
7
+ # Return the check class a config names
8
+ #
9
+ # @param [Symbol, String] name the check's underscored name, such as
10
+ # :mem_usage
11
+ #
12
+ # @return [Class] the ProcessCondition subclass, such as MemUsage
13
+ #
14
+ # @raise [NameError] when no check has that name
15
+ #
16
+ # @api private
3
17
  def self.[](name)
4
18
  const_get(name.to_s.camelcase)
5
19
  end
@@ -7,6 +21,6 @@ module Bluepill
7
21
  end
8
22
 
9
23
  require 'bluepill/process_conditions/process_condition'
10
- Dir["#{File.dirname(__FILE__)}/process_conditions/*.rb"].each do |pc|
24
+ Dir["#{File.dirname(__FILE__)}/process_conditions/*.rb"].sort.each do |pc|
11
25
  require pc
12
26
  end