bluepill 0.2.9 → 0.3.2

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 (95) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +111 -2
  3. data/README.md +16 -13
  4. data/bin/bluepill +21 -8
  5. data/bluepill.gemspec +7 -2
  6. data/lib/bluepill/application/lifecycle.rb +48 -35
  7. data/lib/bluepill/application/listener.rb +2 -4
  8. data/lib/bluepill/application/previous_daemon.rb +12 -14
  9. data/lib/bluepill/application.rb +36 -30
  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 +46 -54
  14. data/lib/bluepill/controller/directory.rb +1 -3
  15. data/lib/bluepill/controller.rb +35 -37
  16. data/lib/bluepill/daemonize.rb +52 -0
  17. data/lib/bluepill/dsl/app_proxy.rb +68 -64
  18. data/lib/bluepill/dsl/attributes.rb +135 -0
  19. data/lib/bluepill/dsl/process_factory/child_factory.rb +83 -0
  20. data/lib/bluepill/dsl/process_factory/registry.rb +4 -26
  21. data/lib/bluepill/dsl/process_factory.rb +85 -84
  22. data/lib/bluepill/dsl/process_proxy.rb +80 -160
  23. data/lib/bluepill/dsl.rb +16 -15
  24. data/lib/bluepill/errors.rb +190 -0
  25. data/lib/bluepill/group.rb +14 -37
  26. data/lib/bluepill/logger.rb +65 -99
  27. data/lib/bluepill/process/attributes.rb +66 -32
  28. data/lib/bluepill/process/children.rb +6 -7
  29. data/lib/bluepill/process/pid.rb +43 -35
  30. data/lib/bluepill/process/state_machine.rb +15 -59
  31. data/lib/bluepill/process/stop_signals.rb +123 -0
  32. data/lib/bluepill/process/transition.rb +1 -3
  33. data/lib/bluepill/process/transition_callbacks.rb +2 -16
  34. data/lib/bluepill/process/triggers.rb +90 -0
  35. data/lib/bluepill/process/user_commands.rb +1 -1
  36. data/lib/bluepill/process/watches.rb +9 -23
  37. data/lib/bluepill/process.rb +55 -52
  38. data/lib/bluepill/process_commands/execution.rb +16 -24
  39. data/lib/bluepill/process_commands/hooks.rb +1 -31
  40. data/lib/bluepill/process_commands/stop_signals.rb +12 -17
  41. data/lib/bluepill/process_commands.rb +10 -8
  42. data/lib/bluepill/process_conditions/always_true.rb +2 -6
  43. data/lib/bluepill/process_conditions/below_threshold.rb +6 -8
  44. data/lib/bluepill/process_conditions/cpu_usage.rb +1 -4
  45. data/lib/bluepill/process_conditions/file_time.rb +8 -9
  46. data/lib/bluepill/process_conditions/http.rb +29 -67
  47. data/lib/bluepill/process_conditions/mem_usage.rb +7 -45
  48. data/lib/bluepill/process_conditions/process_condition.rb +29 -47
  49. data/lib/bluepill/process_conditions/zombie_process.rb +2 -6
  50. data/lib/bluepill/process_conditions.rb +5 -14
  51. data/lib/bluepill/process_journal/cleanup.rb +5 -53
  52. data/lib/bluepill/process_journal/config.rb +73 -0
  53. data/lib/bluepill/process_journal/entries.rb +128 -0
  54. data/lib/bluepill/process_journal/journal.rb +69 -0
  55. data/lib/bluepill/process_journal/kind.rb +60 -0
  56. data/lib/bluepill/process_journal/lock.rb +9 -4
  57. data/lib/bluepill/process_journal.rb +13 -324
  58. data/lib/bluepill/process_statistics.rb +3 -7
  59. data/lib/bluepill/socket.rb +19 -17
  60. data/lib/bluepill/system/command_options.rb +136 -0
  61. data/lib/bluepill/system/command_result.rb +73 -0
  62. data/lib/bluepill/system/command_setup.rb +3 -4
  63. data/lib/bluepill/system/command_spawn.rb +244 -0
  64. data/lib/bluepill/system/commands.rb +27 -40
  65. data/lib/bluepill/system/daemon.rb +97 -15
  66. data/lib/bluepill/system/files.rb +35 -0
  67. data/lib/bluepill/system/ps.rb +20 -17
  68. data/lib/bluepill/system/ps_table.rb +7 -9
  69. data/lib/bluepill/system/usage.rb +175 -0
  70. data/lib/bluepill/system.rb +7 -192
  71. data/lib/bluepill/trigger.rb +18 -69
  72. data/lib/bluepill/triggers/flapping.rb +12 -8
  73. data/lib/bluepill/units.rb +7 -21
  74. data/lib/bluepill/version.rb +16 -26
  75. data/lib/bluepill.rb +1 -1
  76. data/sig/bluepill/application.rbs +11 -12
  77. data/sig/bluepill/attributes.rbs +48 -0
  78. data/sig/bluepill/checks.rbs +40 -40
  79. data/sig/bluepill/dsl.rbs +100 -59
  80. data/sig/bluepill/errors.rbs +48 -0
  81. data/sig/bluepill/logger.rbs +15 -31
  82. data/sig/bluepill/process.rbs +39 -305
  83. data/sig/bluepill/process_commands.rbs +235 -0
  84. data/sig/bluepill/stop_signals.rbs +21 -0
  85. data/sig/bluepill/system.rbs +191 -101
  86. data/sig/bluepill/version.rbs +17 -0
  87. data/sig/bluepill.rbs +2 -17
  88. data/sig/manifest.yaml +1 -0
  89. metadata +22 -8
  90. data/lib/bluepill/deprecation/custom_checks.rb +0 -193
  91. data/lib/bluepill/deprecation/dsl.rb +0 -141
  92. data/lib/bluepill/deprecation/options.rb +0 -140
  93. data/lib/bluepill/deprecation.rb +0 -92
  94. data/lib/bluepill/dsl/process_factory/children.rb +0 -99
  95. data/sig/bluepill/deprecation.rbs +0 -87
@@ -1,193 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Bluepill
4
- module Deprecation
5
- # The directory of bluepill's own code, which a custom check isn't in
6
- LIB_DIR = File.expand_path("../..", File.dirname(__FILE__))
7
-
8
- # The kinds of Method#parameters that take an argument by position
9
- POSITIONAL = %i[req opt].freeze
10
-
11
- # Warn about what a custom check's class does that 0.3.0 rejects
12
- #
13
- # Bluepill 0.3.0 passes a check's options as keyword arguments, calls
14
- # only check?, needs run and check?, and gives a MemUsage subclass bytes.
15
- #
16
- # @param [Class] klass the check's class
17
- #
18
- # @return [void]
19
- #
20
- # @api private
21
- def self.check_condition_class(klass)
22
- base = ProcessConditions::ProcessCondition
23
- warn_positional_options(klass, "check", 0)
24
- warn_check_methods(klass, base)
25
- return unless klass < ProcessConditions::MemUsage
26
-
27
- warn("bluepill 0.3.0 gives a check that subclasses MemUsage the memory usage in bytes, " \
28
- "where 0.2 gives kilobytes, so the run, check? and format_value of #{klass} " \
29
- "get values 1024 times larger. Change them when you upgrade.")
30
- end
31
-
32
- # Warn about what a custom trigger's class does that 0.3.0 rejects
33
- #
34
- # Bluepill 0.3.0 passes a trigger's options as keyword arguments, and
35
- # needs notify.
36
- #
37
- # @param [Class] klass the trigger's class
38
- #
39
- # @return [void]
40
- #
41
- # @api private
42
- def self.check_trigger_class(klass)
43
- warn_positional_options(klass, "trigger", 1)
44
- return unless klass.instance_method(:notify).owner.equal?(Trigger)
45
-
46
- warn("bluepill 0.3.0 fails the config when a trigger doesn't define notify, " \
47
- "and #{klass} doesn't. Define it, or remove the trigger.")
48
- end
49
-
50
- # Warn about a check or trigger whose initialize didn't keep its logger
51
- #
52
- # Bluepill 0.3.0 gives a check or trigger its logger only through the
53
- # logger: option, which the base class's initialize keeps, so one whose
54
- # initialize doesn't call super has none.
55
- #
56
- # @param [ProcessConditions::ProcessCondition, Trigger] check the check
57
- # or trigger, just made
58
- # @param [Logger, nil] logger the logger it was given
59
- #
60
- # @return [void]
61
- #
62
- # @api private
63
- def self.check_logger(check, logger)
64
- return unless logger && check.logger.nil?
65
-
66
- warn("bluepill 0.3.0 gives #{check.class} its logger only through super, " \
67
- "which its initialize doesn't call, so it has no logger. Call super(**options) in its initialize.")
68
- end
69
-
70
- # Warn when code outside bluepill sets a check's or trigger's logger
71
- #
72
- # Bluepill 0.3.0 removes the logger= of ProcessCondition and Trigger.
73
- #
74
- # @param [ProcessConditions::ProcessCondition, Trigger] check the check
75
- # or trigger whose logger is set
76
- # @param [Thread::Backtrace::Location, nil] location where logger= was
77
- # called from
78
- #
79
- # @return [void]
80
- #
81
- # @api private
82
- def self.check_logger_writer(check, location)
83
- path = location&.path
84
- return if path.nil? || File.expand_path(path).start_with?(LIB_DIR)
85
-
86
- warn("bluepill 0.3.0 removes the logger= of checks and triggers, which #{location} " \
87
- "calls on #{check.class}. Let it get its logger from super(**options) in its initialize.")
88
- end
89
-
90
- # Warn about a trigger that dispatches an event that isn't a Symbol
91
- #
92
- # Bluepill 0.3.0 takes only the Symbols of a process's events.
93
- #
94
- # @param [Trigger] trigger the trigger
95
- # @param [Object] event the event it dispatches
96
- #
97
- # @return [void]
98
- #
99
- # @api private
100
- def self.check_trigger_event(trigger, event)
101
- return if event.instance_of?(Symbol)
102
-
103
- warn("bluepill 0.3.0 takes a process's events only as Symbols, so #{trigger.class} " \
104
- "fails when it dispatches #{event.inspect}. Dispatch #{event.to_s.to_sym.inspect}, which 0.2.9 takes too.")
105
- end
106
-
107
- # Warn about a custom initialize that takes its options by position
108
- #
109
- # @param [Class] klass the check's or trigger's class
110
- # @param [String] kind "check" or "trigger"
111
- # @param [Integer] positional how many arguments 0.3.0 passes by
112
- # position, 1 for a trigger's process
113
- #
114
- # @return [void]
115
- #
116
- # @api private
117
- def self.warn_positional_options(klass, kind, positional)
118
- initialize = klass.instance_method(:initialize)
119
- return unless custom?(initialize) && positional_options?(initialize, positional)
120
-
121
- warn("bluepill 0.3.0 passes a #{kind}'s options as keyword arguments, " \
122
- "so the initialize of #{klass}, which takes them as a Hash, fails when it calls super. " \
123
- "Name the options it needs, as in def initialize(path:, below:, **options), " \
124
- "and call super(**options), which 0.2.9 takes too.")
125
- end
126
-
127
- # Warn about a custom check that defines check, or not run and check?
128
- #
129
- # @param [Class] klass the check's class
130
- # @param [Class] base ProcessConditions::ProcessCondition
131
- #
132
- # @return [void]
133
- #
134
- # @api private
135
- def self.warn_check_methods(klass, base)
136
- defines_check = !klass.instance_method(:check).owner.equal?(base)
137
- defines_predicate = !klass.instance_method(:check?).owner.equal?(base)
138
- if defines_check && !defines_predicate
139
- warn("bluepill 0.3.0 calls only check?, so #{klass}, which defines check, fails the config. " \
140
- "Rename its check method check?, which 0.2.9 calls too.")
141
- end
142
- warn_missing_methods(klass, base, defines_check || defines_predicate)
143
- end
144
-
145
- # Warn about a custom check that doesn't define run, or check? or check
146
- #
147
- # @param [Class] klass the check's class
148
- # @param [Class] base ProcessConditions::ProcessCondition
149
- # @param [Boolean] checks whether it defines check? or check
150
- #
151
- # @return [void]
152
- #
153
- # @api private
154
- def self.warn_missing_methods(klass, base, checks)
155
- missing = [] #: Array[String]
156
- missing << "run" if klass.instance_method(:run).owner.equal?(base)
157
- missing << "check?" unless checks
158
- return if missing.empty?
159
-
160
- warn("bluepill 0.3.0 fails the config when a check doesn't define run and check?, " \
161
- "and #{klass} doesn't define #{missing.join(" or ")}. Define it, or remove the check.")
162
- end
163
-
164
- # Return whether a method is defined outside bluepill's own code
165
- #
166
- # @param [UnboundMethod] method the method
167
- #
168
- # @return [Boolean] true for a method of a pill file or a library
169
- #
170
- # @api private
171
- def self.custom?(method)
172
- file, = method.source_location
173
- !file.nil? && !File.expand_path(file).start_with?(LIB_DIR)
174
- end
175
-
176
- # Return whether an initialize takes options by position
177
- #
178
- # It does if it takes more arguments by position than 0.3.0 passes.
179
- #
180
- # @param [UnboundMethod] initialize the initialize method
181
- # @param [Integer] positional how many arguments 0.3.0 passes by
182
- # position
183
- #
184
- # @return [Boolean]
185
- #
186
- # @api private
187
- def self.positional_options?(initialize, positional)
188
- parameters = initialize.parameters
189
- parameters.any? { |type, _| type.equal?(:rest) } ||
190
- parameters.count { |type, _| POSITIONAL.include?(type) } > positional
191
- end
192
- end
193
- end
@@ -1,141 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Bluepill
4
- module Deprecation
5
- # The attributes that 0.3.0 doesn't let a process block set
6
- CHILD_ATTRIBUTES = %i[monitor_children child_process_factory].freeze
7
-
8
- # Warn about a way of setting a process attribute that 0.3.0 removes
9
- #
10
- # Bluepill 0.3.0 sets an attribute only with `name = value`, so
11
- # `name!` and `name value` fail, and a process block can't set
12
- # monitor_children or child_process_factory.
13
- #
14
- # @param [Symbol] name the method the pill file called, such as
15
- # :daemonize!
16
- # @param [Symbol] key the attribute, such as :daemonize
17
- #
18
- # @return [void]
19
- #
20
- # @api private
21
- def self.check_attribute(name, key)
22
- if name.end_with?("!")
23
- warn("bluepill 0.3.0 removes process.#{name}. Write process.#{key} = true, which 0.2 takes too.")
24
- elsif !name.end_with?("=")
25
- warn("bluepill 0.3.0 removes process.#{key} value. Write process.#{key} = value, which 0.2 takes too.")
26
- end
27
- return unless CHILD_ATTRIBUTES.include?(key)
28
-
29
- warn("bluepill 0.3.0 doesn't let a process block set #{key}. " \
30
- "Call process.monitor_children with a block that configures the children, which 0.2 takes too.")
31
- end
32
-
33
- # Warn about monitor_children without a block, which 0.3.0 rejects
34
- #
35
- # @param [String] process_name the process's name
36
- # @param [Proc, nil] block the block that configures the children
37
- #
38
- # @return [void]
39
- #
40
- # @api private
41
- def self.check_monitor_children(process_name, block)
42
- return if block
43
-
44
- warn("bluepill 0.3.0 fails the config when monitor_children has no block, " \
45
- "as for process '#{process_name}'. Give it a block that sets the children's stop_command.")
46
- end
47
-
48
- # Warn about a monitor_children block that sets no stop_command
49
- #
50
- # @param [String] parent_name the parent process's name
51
- # @param [Hash{Symbol => Object}] attributes the attributes that the
52
- # block set on a child
53
- #
54
- # @return [void]
55
- #
56
- # @api private
57
- def self.check_child_stop_command(parent_name, attributes)
58
- return if attributes.key?(:stop_command)
59
-
60
- warn("bluepill 0.3.0 fails the config when a monitor_children block sets no stop_command, " \
61
- "as for the children of '#{parent_name}', where 0.2 exits the daemon when it first finds a child. " \
62
- "Set the children's stop_command in the block.")
63
- end
64
-
65
- # Warn about a daemon older than 0.2.9, which 0.3.0's CLI refuses
66
- #
67
- # A daemon older than 0.2.9 answers the CLI with its Version module,
68
- # which Marshal loads as the CLI's own.
69
- #
70
- # @param [Module, String] version what the daemon answered
71
- #
72
- # @return [void]
73
- #
74
- # @api private
75
- def self.check_daemon_version(version)
76
- return if version.instance_of?(String)
77
-
78
- warn("this daemon runs a bluepill older than 0.2.9, which the CLI of bluepill 0.3.0 says is out of date. " \
79
- "Run bluepill load again, so the daemon runs this version.")
80
- end
81
-
82
- # The options that 0.3.0's Bluepill.application takes
83
- APPLICATION_OPTIONS = %i[foreground log_file log_level base_dir kill_timeout].freeze
84
-
85
- # Warn about options passed as a Hash, without **
86
- #
87
- # Bluepill 0.3.0 takes the options of Bluepill.application and checks
88
- # as keyword arguments, and Ruby 3 keeps a Hash passed without ** as a
89
- # positional argument, which fails. Ruby 2.7 passes such a Hash as
90
- # keywords, so it can't tell, and warns about none.
91
- #
92
- # @param [Hash{Symbol => Object}, nil] options the options passed as a
93
- # Hash, or nil for none
94
- # @param [Hash{Symbol => Object}] keywords the options passed as
95
- # keywords
96
- # @param [String] call the call, as the message shows it, such as
97
- # "process.checks :mem_usage"
98
- #
99
- # @return [void]
100
- #
101
- # @raise [ArgumentError] for options passed both ways, which 0.2.7
102
- # rejected as too many arguments
103
- #
104
- # @api private
105
- def self.check_keywords(options, keywords, call)
106
- return unless options
107
- raise ArgumentError, "wrong number of arguments (given 3, expected 1..2)" unless keywords.empty?
108
-
109
- warn("bluepill 0.3.0 takes the options of #{call} only as keyword arguments, " \
110
- "so options kept in a Hash fail unless they're passed with **. Write #{call}, **options, which 0.2 takes too.")
111
- end
112
-
113
- # Warn about an application option that 0.3.0 rejects
114
- #
115
- # @param [Hash{Symbol => Object}] options the application's options
116
- #
117
- # @return [void]
118
- #
119
- # @api private
120
- def self.check_application_options(options)
121
- (options.keys - APPLICATION_OPTIONS).each do |option|
122
- warn("bluepill 0.3.0 rejects the application option #{option}:, which 0.2 ignores. " \
123
- "Remove it, or fix its name.")
124
- end
125
- end
126
-
127
- # Warn about a second check of the same name in a process
128
- #
129
- # Bluepill 0.2 keeps only the last of them, and 0.3.0 runs them all.
130
- #
131
- # @param [Symbol] name the check's name
132
- #
133
- # @return [void]
134
- #
135
- # @api private
136
- def self.check_duplicate_check(name)
137
- warn("bluepill 0.3.0 runs every check of a process, so a process with two checks #{name.inspect} runs both, " \
138
- "where 0.2 runs only the last. Remove the one you don't want.")
139
- end
140
- end
141
- end
@@ -1,140 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Bluepill
4
- module Deprecation
5
- # The events that 0.3.0 takes for fires: and on_start_timeout
6
- EVENTS = %i[start stop unmonitor restart].freeze
7
-
8
- # The events, as a message lists them
9
- EVENTS_LIST = ":start, :stop, :unmonitor or :restart"
10
-
11
- no_options = [] #: Array[Symbol]
12
-
13
- # The options of a check that takes none of its own, made once
14
- NO_OPTIONS = no_options.freeze
15
-
16
- # The options that each of bluepill's checks and triggers takes in 0.3.0
17
- CHECK_OPTIONS = {
18
- always_true: NO_OPTIONS,
19
- cpu_usage: %i[below],
20
- file_time: %i[filename below],
21
- flapping: %i[times within retry_in],
22
- http: %i[url kind pattern timeout open_timeout read_timeout verify_ssl],
23
- mem_usage: %i[below],
24
- running_time: %i[below],
25
- zombie_process: NO_OPTIONS
26
- }.freeze
27
-
28
- # The options that 0.3.0 needs, of the checks that need any
29
- #
30
- # An http check's url: isn't here, since 0.2 already fails without it.
31
- REQUIRED_OPTIONS = {
32
- cpu_usage: %i[below],
33
- file_time: %i[filename below],
34
- mem_usage: %i[below],
35
- running_time: %i[below]
36
- }.freeze
37
-
38
- # Warn about the options of a check that 0.3.0 rejects or needs
39
- #
40
- # Bluepill 0.3.0 fails the config for an option that a check doesn't
41
- # take, such as a misspelled one or within: on an http check, and for
42
- # one it needs and doesn't have, such as below: on a mem_usage check.
43
- # A custom check's options are its own business.
44
- #
45
- # @param [Symbol, String] name the check's name, such as :mem_usage
46
- # @param [Hash{Symbol => Object}] options the check's options
47
- # @param [Array<Symbol>] taken the options that bluepill takes for
48
- # itself, ConditionWatch::WATCH_KEYS, or none for a trigger
49
- #
50
- # @return [void]
51
- #
52
- # @api private
53
- def self.check_options(name, options, taken)
54
- check = name.to_sym
55
- known = CHECK_OPTIONS[check]
56
- return unless known
57
-
58
- warn_unknown_options(check, options.keys - taken - known)
59
- warn_missing_options(check, REQUIRED_OPTIONS.fetch(check, NO_OPTIONS) - options.keys)
60
- end
61
-
62
- # Warn about the options of one of bluepill's checks that it doesn't take
63
- #
64
- # @param [Symbol] check the check's name
65
- # @param [Array<Object>] unknown the options
66
- #
67
- # @return [void]
68
- #
69
- # @api private
70
- def self.warn_unknown_options(check, unknown)
71
- unknown.each do |option|
72
- warn("bluepill 0.3.0 rejects the option #{option}: of checks #{check.inspect}, which 0.2 ignores. " \
73
- "Remove it, or fix its name.")
74
- end
75
- end
76
-
77
- # Warn about the options that one of bluepill's checks needs
78
- #
79
- # @param [Symbol] check the check's name
80
- # @param [Array<Symbol>] missing the options it doesn't have
81
- #
82
- # @return [void]
83
- #
84
- # @api private
85
- def self.warn_missing_options(check, missing)
86
- missing.each do |option|
87
- warn("bluepill 0.3.0 fails the config when checks #{check.inspect} has no #{option}: option, " \
88
- "which it needs to check anything in 0.2 too. Add it.")
89
- end
90
- end
91
-
92
- # Warn about a watch's options and events that 0.3.0 rejects
93
- #
94
- # @param [Symbol, String] name the check's name
95
- # @param [Hash{Symbol => Object}] options the watch's options
96
- # @param [Array<Object>] events the events it fires
97
- #
98
- # @return [void]
99
- #
100
- # @api private
101
- def self.check_watch(name, options, events)
102
- check_options(name, options, ConditionWatch::WATCH_KEYS)
103
- check_fires(name, events)
104
- end
105
-
106
- # Warn about events of a check's fires: that 0.3.0 rejects
107
- #
108
- # @param [Symbol, String] name the check's name
109
- # @param [Array<Object>] events the events it fires
110
- #
111
- # @return [void]
112
- #
113
- # @api private
114
- def self.check_fires(name, events)
115
- unknown = events - EVENTS
116
- return if unknown.empty?
117
-
118
- warn("bluepill 0.3.0 takes fires: only as #{EVENTS_LIST}, so fires: #{unknown.collect(&:inspect).join(", ")} " \
119
- "of checks #{name.to_sym.inspect} fails the config. Use the Symbols, such as fires: :stop.")
120
- end
121
-
122
- # Warn about a process's on_start_timeout that 0.3.0 rejects
123
- #
124
- # @param [String] process_name the process's name
125
- # @param [Hash{Symbol => Object}] attributes the process's attributes
126
- #
127
- # @return [void]
128
- #
129
- # @api private
130
- def self.check_on_start_timeout(process_name, attributes)
131
- return unless attributes.key?(:on_start_timeout)
132
-
133
- event = attributes.fetch(:on_start_timeout)
134
- return if EVENTS.include?(event)
135
-
136
- warn("bluepill 0.3.0 takes on_start_timeout only as #{EVENTS_LIST}, so process '#{process_name}''s " \
137
- "on_start_timeout of #{event.inspect} fails the config. Use the Symbols, such as on_start_timeout = :unmonitor.")
138
- end
139
- end
140
- end
@@ -1,92 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "set"
4
-
5
- module Bluepill
6
- # Warn, once each, about what bluepill 0.3.0 changes
7
- #
8
- # `bluepill load` loads a pill file before the daemon detaches, so a
9
- # warning goes to stderr, where the user sees it, and to bluepill's log at
10
- # warning, once there's a logger. Each warning names what it's about, so
11
- # it's given once for each message.
12
- #
13
- # @example
14
- # Bluepill::Deprecation.warn("bluepill 0.3.0 rejects the check option evry:. Remove it, or fix its name.")
15
- # # DEPRECATION: bluepill 0.3.0 rejects the check option evry:. Remove it, or fix its name.
16
- #
17
- # @api private
18
- module Deprecation
19
- # The major version of the Ruby that bluepill 0.3.0 needs, or newer
20
- RUBY_REQUIRED = 3
21
-
22
- @warned = Set.new #: Set[String]
23
- @logger = nil #: Logger?
24
-
25
- # Warn about a change, unless the same warning was given
26
- #
27
- # @param [String] message what changes, in which version, and what to
28
- # do now
29
- #
30
- # @return [void]
31
- #
32
- # @api private
33
- def self.warn(message)
34
- return unless @warned.add?(message)
35
-
36
- line = "DEPRECATION: #{message}"
37
- $stderr.puts(line)
38
- @logger&.warning(line)
39
- end
40
-
41
- # Return the logger the warnings also go to
42
- #
43
- # @return [Logger, nil] the application's logger, or nil before there's
44
- # one
45
- #
46
- # @api private
47
- def self.logger
48
- @logger
49
- end
50
-
51
- # Set the logger the warnings also go to
52
- #
53
- # @param [Logger, nil] logger the application's logger
54
- #
55
- # @return [void]
56
- #
57
- # @api private
58
- def self.logger=(logger)
59
- @logger = logger
60
- end
61
-
62
- # Forget the warnings given and the logger
63
- #
64
- # The specs call it before each example.
65
- #
66
- # @return [void]
67
- #
68
- # @api private
69
- def self.reset!
70
- @warned.clear
71
- @logger = nil
72
- end
73
-
74
- # Warn when bluepill runs on a Ruby that 0.3.0 doesn't support
75
- #
76
- # @param [String] version the Ruby's version
77
- #
78
- # @return [void]
79
- #
80
- # @api private
81
- def self.check_ruby(version = RUBY_VERSION)
82
- return unless version.to_i < RUBY_REQUIRED
83
-
84
- warn("bluepill 0.3.0 needs Ruby 3.0 or newer, or JRuby 9.4 or newer, and this is Ruby #{version}. " \
85
- "Upgrade Ruby before you upgrade bluepill, or stay on 0.2.9.")
86
- end
87
- end
88
- end
89
-
90
- require "bluepill/deprecation/custom_checks"
91
- require "bluepill/deprecation/options"
92
- require "bluepill/deprecation/dsl"
@@ -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