bluepill 0.2.9 → 0.3.0

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 (93) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +100 -2
  3. data/README.md +12 -7
  4. data/bin/bluepill +8 -2
  5. data/bluepill.gemspec +1 -1
  6. data/lib/bluepill/application/lifecycle.rb +44 -34
  7. data/lib/bluepill/application/listener.rb +1 -1
  8. data/lib/bluepill/application/previous_daemon.rb +12 -14
  9. data/lib/bluepill/application.rb +33 -29
  10. data/lib/bluepill/base_directory.rb +18 -20
  11. data/lib/bluepill/check_registry.rb +104 -0
  12. data/lib/bluepill/clock.rb +1 -3
  13. data/lib/bluepill/condition_watch.rb +45 -54
  14. data/lib/bluepill/controller/directory.rb +1 -3
  15. data/lib/bluepill/controller.rb +32 -37
  16. data/lib/bluepill/dsl/app_proxy.rb +68 -64
  17. data/lib/bluepill/dsl/attributes.rb +135 -0
  18. data/lib/bluepill/dsl/process_factory/child_factory.rb +80 -0
  19. data/lib/bluepill/dsl/process_factory/registry.rb +6 -26
  20. data/lib/bluepill/dsl/process_factory.rb +83 -84
  21. data/lib/bluepill/dsl/process_proxy.rb +61 -168
  22. data/lib/bluepill/dsl.rb +16 -15
  23. data/lib/bluepill/errors.rb +190 -0
  24. data/lib/bluepill/group.rb +14 -37
  25. data/lib/bluepill/logger.rb +55 -97
  26. data/lib/bluepill/process/attributes.rb +66 -32
  27. data/lib/bluepill/process/children.rb +4 -6
  28. data/lib/bluepill/process/pid.rb +41 -35
  29. data/lib/bluepill/process/state_machine.rb +15 -59
  30. data/lib/bluepill/process/stop_signals.rb +120 -0
  31. data/lib/bluepill/process/transition.rb +1 -3
  32. data/lib/bluepill/process/transition_callbacks.rb +2 -16
  33. data/lib/bluepill/process/triggers.rb +90 -0
  34. data/lib/bluepill/process/user_commands.rb +1 -1
  35. data/lib/bluepill/process/watches.rb +9 -23
  36. data/lib/bluepill/process.rb +55 -52
  37. data/lib/bluepill/process_commands/execution.rb +14 -22
  38. data/lib/bluepill/process_commands/hooks.rb +1 -31
  39. data/lib/bluepill/process_commands/stop_signals.rb +12 -17
  40. data/lib/bluepill/process_commands.rb +10 -8
  41. data/lib/bluepill/process_conditions/always_true.rb +2 -6
  42. data/lib/bluepill/process_conditions/below_threshold.rb +6 -8
  43. data/lib/bluepill/process_conditions/cpu_usage.rb +1 -4
  44. data/lib/bluepill/process_conditions/file_time.rb +8 -9
  45. data/lib/bluepill/process_conditions/http.rb +28 -67
  46. data/lib/bluepill/process_conditions/mem_usage.rb +7 -45
  47. data/lib/bluepill/process_conditions/process_condition.rb +29 -47
  48. data/lib/bluepill/process_conditions/zombie_process.rb +2 -6
  49. data/lib/bluepill/process_conditions.rb +5 -14
  50. data/lib/bluepill/process_journal/cleanup.rb +5 -53
  51. data/lib/bluepill/process_journal/config.rb +73 -0
  52. data/lib/bluepill/process_journal/entries.rb +128 -0
  53. data/lib/bluepill/process_journal/journal.rb +69 -0
  54. data/lib/bluepill/process_journal/kind.rb +60 -0
  55. data/lib/bluepill/process_journal/lock.rb +9 -4
  56. data/lib/bluepill/process_journal.rb +13 -324
  57. data/lib/bluepill/process_statistics.rb +3 -7
  58. data/lib/bluepill/socket.rb +19 -17
  59. data/lib/bluepill/system/command_options.rb +135 -0
  60. data/lib/bluepill/system/command_result.rb +73 -0
  61. data/lib/bluepill/system/command_setup.rb +3 -4
  62. data/lib/bluepill/system/commands.rb +21 -18
  63. data/lib/bluepill/system/daemon.rb +19 -14
  64. data/lib/bluepill/system/files.rb +35 -0
  65. data/lib/bluepill/system/ps.rb +20 -17
  66. data/lib/bluepill/system/ps_table.rb +7 -9
  67. data/lib/bluepill/system/usage.rb +155 -0
  68. data/lib/bluepill/system.rb +7 -192
  69. data/lib/bluepill/trigger.rb +18 -69
  70. data/lib/bluepill/triggers/flapping.rb +12 -8
  71. data/lib/bluepill/units.rb +7 -21
  72. data/lib/bluepill/version.rb +12 -22
  73. data/lib/bluepill.rb +1 -1
  74. data/sig/bluepill/application.rbs +11 -12
  75. data/sig/bluepill/attributes.rbs +48 -0
  76. data/sig/bluepill/checks.rbs +40 -40
  77. data/sig/bluepill/dsl.rbs +97 -60
  78. data/sig/bluepill/errors.rbs +48 -0
  79. data/sig/bluepill/logger.rbs +15 -31
  80. data/sig/bluepill/process.rbs +39 -305
  81. data/sig/bluepill/process_commands.rbs +235 -0
  82. data/sig/bluepill/stop_signals.rbs +21 -0
  83. data/sig/bluepill/system.rbs +154 -99
  84. data/sig/bluepill/version.rbs +17 -0
  85. data/sig/bluepill.rbs +1 -17
  86. data/sig/manifest.yaml +1 -0
  87. metadata +21 -8
  88. data/lib/bluepill/deprecation/custom_checks.rb +0 -193
  89. data/lib/bluepill/deprecation/dsl.rb +0 -141
  90. data/lib/bluepill/deprecation/options.rb +0 -140
  91. data/lib/bluepill/deprecation.rb +0 -92
  92. data/lib/bluepill/dsl/process_factory/children.rb +0 -99
  93. data/sig/bluepill/deprecation.rbs +0 -87
@@ -1,99 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Bluepill
4
- class ProcessFactory
5
- # Create the processes of the children that a process's factory finds
6
- #
7
- # A process that monitors its children gets a factory of its own, with
8
- # the process block that configures each child. Process asks it for a
9
- # child's process when it finds a new child.
10
- #
11
- # @api private
12
- module Children
13
- # Create the process of a child that bluepill found
14
- #
15
- # The child gets its parent's grace times, the parent's user and groups,
16
- # so its commands run as the parent's do, and its state from whether
17
- # it's running.
18
- #
19
- # @param [String] name the child's name
20
- # @param [Integer] pid the child's pid
21
- # @param [Logger] logger the child's logger
22
- #
23
- # @return [Process] the child's process
24
- #
25
- # @api private
26
- def create_child_process(name, pid, logger)
27
- attributes = inherited_attributes
28
- attributes[:actual_pid] = pid
29
- attributes[:logger] = logger
30
-
31
- child = ProcessProxy.new(name, attributes, @process_block)
32
- validate_child_process! child
33
- process = child.to_process
34
-
35
- process.determine_initial_state
36
- process
37
- end
38
-
39
- # Warn about what 0.3.0 rejects in the children's block
40
- #
41
- # It runs while the pill file loads.
42
- #
43
- # Bluepill 0.3.0 runs the block once when the pill file loads, for a
44
- # child whose pid isn't known yet, and fails the config for a mistake
45
- # in it, such as a missing stop_command, where 0.2 exits the daemon
46
- # the first time it finds a child. This runs the block the same way,
47
- # to warn about the mistakes and about the checks that the children
48
- # get. A block that raises for such a child, or no block, which
49
- # monitor_children has warned about, warns about nothing.
50
- #
51
- # @param [String] parent_name the parent process's name
52
- #
53
- # @return [void]
54
- #
55
- # @api private
56
- def check_children(parent_name)
57
- child = ProcessProxy.new("<child of #{parent_name}>", inherited_attributes, @process_block)
58
- Deprecation.check_on_start_timeout(child.name, child.attributes)
59
- Deprecation.check_child_stop_command(parent_name, child.attributes)
60
- child.to_process
61
- rescue
62
- nil
63
- end
64
-
65
- protected
66
-
67
- # Return the attributes a child gets from its parent
68
- #
69
- # These are the grace times, user and groups that the parent sets.
70
- #
71
- # @return [Hash{Symbol => Object}] the attributes
72
- #
73
- # @api private
74
- def inherited_attributes
75
- attributes = {} #: Hash[Symbol, untyped]
76
- # A grace time the parent leaves unset keeps the Process default
77
- %i[start_grace_time stop_grace_time restart_grace_time uid gid supplementary_groups].each do |a|
78
- attributes[a] = @attributes.fetch(a) if @attributes.key?(a)
79
- end
80
- attributes
81
- end
82
-
83
- # Exit unless a monitored child has a stop_command
84
- #
85
- # @param [ProcessProxy] child the child's proxy
86
- #
87
- # @return [void]
88
- #
89
- # @api private
90
- def validate_child_process!(child)
91
- return if child.attributes.key?(:stop_command)
92
-
93
- $stderr.puts "Config Error: Invalid child process monitor for #{child.name}"
94
- $stderr.puts "You must specify a stop command to monitor child processes."
95
- exit(6)
96
- end
97
- end
98
- end
99
- end
@@ -1,87 +0,0 @@
1
- module Bluepill
2
- # Warns, once each, about what bluepill 0.3.0 changes
3
- module Deprecation
4
- RUBY_REQUIRED: Integer
5
-
6
- self.@warned: Set[String]
7
- self.@logger: Logger?
8
-
9
- # Warns about a change, unless the same warning was given
10
- def self.warn: (String message) -> void
11
-
12
- def self.logger: () -> Logger?
13
-
14
- def self.logger=: (Logger? logger) -> void
15
-
16
- # Forgets the warnings given and the logger
17
- def self.reset!: () -> void
18
-
19
- # Warns when bluepill runs on a Ruby that 0.3.0 doesn't support
20
- def self.check_ruby: (?String version) -> void
21
-
22
- LIB_DIR: String
23
- POSITIONAL: Array[Symbol]
24
-
25
- # Warns about what a custom check's class does that 0.3.0 rejects
26
- def self.check_condition_class: (Class klass) -> void
27
-
28
- # Warns about what a custom trigger's class does that 0.3.0 rejects
29
- def self.check_trigger_class: (Class klass) -> void
30
-
31
- def self.check_logger: (ProcessConditions::ProcessCondition[untyped] | Trigger check, Logger? logger) -> void
32
-
33
- def self.check_logger_writer: (ProcessConditions::ProcessCondition[untyped] | Trigger check, Thread::Backtrace::Location? location) -> void
34
-
35
- def self.check_trigger_event: (Trigger trigger, untyped event) -> void
36
-
37
- def self.warn_positional_options: (Class klass, String kind, Integer positional) -> void
38
-
39
- def self.warn_check_methods: (Class klass, Class base) -> void
40
-
41
- def self.warn_missing_methods: (Class klass, Class base, bool checks) -> void
42
-
43
- def self.custom?: (UnboundMethod method) -> bool
44
-
45
- def self.positional_options?: (UnboundMethod initialize, Integer positional) -> bool
46
-
47
- CHILD_ATTRIBUTES: Array[Symbol]
48
-
49
- # Warns about a way of setting a process attribute that 0.3.0 removes
50
- def self.check_attribute: (Symbol name, Symbol key) -> void
51
-
52
- def self.check_monitor_children: (String process_name, Proc? block) -> void
53
-
54
- def self.check_child_stop_command: (String parent_name, Hash[Symbol, untyped] attributes) -> void
55
-
56
- def self.check_daemon_version: (Module | String version) -> void
57
-
58
- APPLICATION_OPTIONS: Array[Symbol]
59
-
60
- # Warns about options passed as a Hash, without **
61
- def self.check_keywords: (Hash[Symbol, untyped]? options, Hash[Symbol, untyped] keywords, String call) -> void
62
-
63
- def self.check_application_options: (Hash[Symbol, untyped] options) -> void
64
-
65
- def self.check_duplicate_check: (Symbol name) -> void
66
-
67
- EVENTS: Array[Symbol]
68
- EVENTS_LIST: String
69
- NO_OPTIONS: Array[Symbol]
70
- CHECK_OPTIONS: Hash[Symbol, Array[Symbol]]
71
- REQUIRED_OPTIONS: Hash[Symbol, Array[Symbol]]
72
-
73
- # Warns about the options of a check that 0.3.0 rejects or needs
74
- def self.check_options: (Symbol | String name, Hash[untyped, untyped] options, Array[Symbol] taken) -> void
75
-
76
- def self.warn_unknown_options: (Symbol check, Array[untyped] unknown) -> void
77
-
78
- def self.warn_missing_options: (Symbol check, Array[Symbol] missing) -> void
79
-
80
- # Warns about a watch's options and events that 0.3.0 rejects
81
- def self.check_watch: (Symbol | String name, Hash[Symbol, untyped] options, Array[untyped] events) -> void
82
-
83
- def self.check_fires: (Symbol | String name, Array[untyped] events) -> void
84
-
85
- def self.check_on_start_timeout: (String process_name, Hash[Symbol, untyped] attributes) -> void
86
- end
87
- end