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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +100 -2
- data/README.md +12 -7
- data/bin/bluepill +8 -2
- data/bluepill.gemspec +1 -1
- data/lib/bluepill/application/lifecycle.rb +44 -34
- data/lib/bluepill/application/listener.rb +1 -1
- data/lib/bluepill/application/previous_daemon.rb +12 -14
- data/lib/bluepill/application.rb +33 -29
- data/lib/bluepill/base_directory.rb +18 -20
- data/lib/bluepill/check_registry.rb +104 -0
- data/lib/bluepill/clock.rb +1 -3
- data/lib/bluepill/condition_watch.rb +45 -54
- data/lib/bluepill/controller/directory.rb +1 -3
- data/lib/bluepill/controller.rb +32 -37
- data/lib/bluepill/dsl/app_proxy.rb +68 -64
- data/lib/bluepill/dsl/attributes.rb +135 -0
- data/lib/bluepill/dsl/process_factory/child_factory.rb +80 -0
- data/lib/bluepill/dsl/process_factory/registry.rb +6 -26
- data/lib/bluepill/dsl/process_factory.rb +83 -84
- data/lib/bluepill/dsl/process_proxy.rb +61 -168
- data/lib/bluepill/dsl.rb +16 -15
- data/lib/bluepill/errors.rb +190 -0
- data/lib/bluepill/group.rb +14 -37
- data/lib/bluepill/logger.rb +55 -97
- data/lib/bluepill/process/attributes.rb +66 -32
- data/lib/bluepill/process/children.rb +4 -6
- data/lib/bluepill/process/pid.rb +41 -35
- data/lib/bluepill/process/state_machine.rb +15 -59
- data/lib/bluepill/process/stop_signals.rb +120 -0
- data/lib/bluepill/process/transition.rb +1 -3
- data/lib/bluepill/process/transition_callbacks.rb +2 -16
- data/lib/bluepill/process/triggers.rb +90 -0
- data/lib/bluepill/process/user_commands.rb +1 -1
- data/lib/bluepill/process/watches.rb +9 -23
- data/lib/bluepill/process.rb +55 -52
- data/lib/bluepill/process_commands/execution.rb +14 -22
- data/lib/bluepill/process_commands/hooks.rb +1 -31
- data/lib/bluepill/process_commands/stop_signals.rb +12 -17
- data/lib/bluepill/process_commands.rb +10 -8
- data/lib/bluepill/process_conditions/always_true.rb +2 -6
- data/lib/bluepill/process_conditions/below_threshold.rb +6 -8
- data/lib/bluepill/process_conditions/cpu_usage.rb +1 -4
- data/lib/bluepill/process_conditions/file_time.rb +8 -9
- data/lib/bluepill/process_conditions/http.rb +28 -67
- data/lib/bluepill/process_conditions/mem_usage.rb +7 -45
- data/lib/bluepill/process_conditions/process_condition.rb +29 -47
- data/lib/bluepill/process_conditions/zombie_process.rb +2 -6
- data/lib/bluepill/process_conditions.rb +5 -14
- data/lib/bluepill/process_journal/cleanup.rb +5 -53
- data/lib/bluepill/process_journal/config.rb +73 -0
- data/lib/bluepill/process_journal/entries.rb +128 -0
- data/lib/bluepill/process_journal/journal.rb +69 -0
- data/lib/bluepill/process_journal/kind.rb +60 -0
- data/lib/bluepill/process_journal/lock.rb +9 -4
- data/lib/bluepill/process_journal.rb +13 -324
- data/lib/bluepill/process_statistics.rb +3 -7
- data/lib/bluepill/socket.rb +19 -17
- data/lib/bluepill/system/command_options.rb +135 -0
- data/lib/bluepill/system/command_result.rb +73 -0
- data/lib/bluepill/system/command_setup.rb +3 -4
- data/lib/bluepill/system/commands.rb +21 -18
- data/lib/bluepill/system/daemon.rb +19 -14
- data/lib/bluepill/system/files.rb +35 -0
- data/lib/bluepill/system/ps.rb +20 -17
- data/lib/bluepill/system/ps_table.rb +7 -9
- data/lib/bluepill/system/usage.rb +155 -0
- data/lib/bluepill/system.rb +7 -192
- data/lib/bluepill/trigger.rb +18 -69
- data/lib/bluepill/triggers/flapping.rb +12 -8
- data/lib/bluepill/units.rb +7 -21
- data/lib/bluepill/version.rb +12 -22
- data/lib/bluepill.rb +1 -1
- data/sig/bluepill/application.rbs +11 -12
- data/sig/bluepill/attributes.rbs +48 -0
- data/sig/bluepill/checks.rbs +40 -40
- data/sig/bluepill/dsl.rbs +97 -60
- data/sig/bluepill/errors.rbs +48 -0
- data/sig/bluepill/logger.rbs +15 -31
- data/sig/bluepill/process.rbs +39 -305
- data/sig/bluepill/process_commands.rbs +235 -0
- data/sig/bluepill/stop_signals.rbs +21 -0
- data/sig/bluepill/system.rbs +154 -99
- data/sig/bluepill/version.rbs +17 -0
- data/sig/bluepill.rbs +1 -17
- data/sig/manifest.yaml +1 -0
- metadata +21 -8
- data/lib/bluepill/deprecation/custom_checks.rb +0 -193
- data/lib/bluepill/deprecation/dsl.rb +0 -141
- data/lib/bluepill/deprecation/options.rb +0 -140
- data/lib/bluepill/deprecation.rb +0 -92
- data/lib/bluepill/dsl/process_factory/children.rb +0 -99
- data/sig/bluepill/deprecation.rbs +0 -87
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bluepill
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Arya Asemanfar
|
|
@@ -38,21 +38,20 @@ files:
|
|
|
38
38
|
- lib/bluepill/application/listener.rb
|
|
39
39
|
- lib/bluepill/application/previous_daemon.rb
|
|
40
40
|
- lib/bluepill/base_directory.rb
|
|
41
|
+
- lib/bluepill/check_registry.rb
|
|
41
42
|
- lib/bluepill/clock.rb
|
|
42
43
|
- lib/bluepill/condition_watch.rb
|
|
43
44
|
- lib/bluepill/controller.rb
|
|
44
45
|
- lib/bluepill/controller/directory.rb
|
|
45
46
|
- lib/bluepill/daemonize.rb
|
|
46
|
-
- lib/bluepill/deprecation.rb
|
|
47
|
-
- lib/bluepill/deprecation/custom_checks.rb
|
|
48
|
-
- lib/bluepill/deprecation/dsl.rb
|
|
49
|
-
- lib/bluepill/deprecation/options.rb
|
|
50
47
|
- lib/bluepill/dsl.rb
|
|
51
48
|
- lib/bluepill/dsl/app_proxy.rb
|
|
49
|
+
- lib/bluepill/dsl/attributes.rb
|
|
52
50
|
- lib/bluepill/dsl/process_factory.rb
|
|
53
|
-
- lib/bluepill/dsl/process_factory/
|
|
51
|
+
- lib/bluepill/dsl/process_factory/child_factory.rb
|
|
54
52
|
- lib/bluepill/dsl/process_factory/registry.rb
|
|
55
53
|
- lib/bluepill/dsl/process_proxy.rb
|
|
54
|
+
- lib/bluepill/errors.rb
|
|
56
55
|
- lib/bluepill/group.rb
|
|
57
56
|
- lib/bluepill/logger.rb
|
|
58
57
|
- lib/bluepill/pid_file.rb
|
|
@@ -61,8 +60,10 @@ files:
|
|
|
61
60
|
- lib/bluepill/process/children.rb
|
|
62
61
|
- lib/bluepill/process/pid.rb
|
|
63
62
|
- lib/bluepill/process/state_machine.rb
|
|
63
|
+
- lib/bluepill/process/stop_signals.rb
|
|
64
64
|
- lib/bluepill/process/transition.rb
|
|
65
65
|
- lib/bluepill/process/transition_callbacks.rb
|
|
66
|
+
- lib/bluepill/process/triggers.rb
|
|
66
67
|
- lib/bluepill/process/user_commands.rb
|
|
67
68
|
- lib/bluepill/process/watches.rb
|
|
68
69
|
- lib/bluepill/process_commands.rb
|
|
@@ -81,15 +82,23 @@ files:
|
|
|
81
82
|
- lib/bluepill/process_conditions/zombie_process.rb
|
|
82
83
|
- lib/bluepill/process_journal.rb
|
|
83
84
|
- lib/bluepill/process_journal/cleanup.rb
|
|
85
|
+
- lib/bluepill/process_journal/config.rb
|
|
86
|
+
- lib/bluepill/process_journal/entries.rb
|
|
87
|
+
- lib/bluepill/process_journal/journal.rb
|
|
88
|
+
- lib/bluepill/process_journal/kind.rb
|
|
84
89
|
- lib/bluepill/process_journal/lock.rb
|
|
85
90
|
- lib/bluepill/process_statistics.rb
|
|
86
91
|
- lib/bluepill/socket.rb
|
|
87
92
|
- lib/bluepill/system.rb
|
|
93
|
+
- lib/bluepill/system/command_options.rb
|
|
94
|
+
- lib/bluepill/system/command_result.rb
|
|
88
95
|
- lib/bluepill/system/command_setup.rb
|
|
89
96
|
- lib/bluepill/system/commands.rb
|
|
90
97
|
- lib/bluepill/system/daemon.rb
|
|
98
|
+
- lib/bluepill/system/files.rb
|
|
91
99
|
- lib/bluepill/system/ps.rb
|
|
92
100
|
- lib/bluepill/system/ps_table.rb
|
|
101
|
+
- lib/bluepill/system/usage.rb
|
|
93
102
|
- lib/bluepill/trigger.rb
|
|
94
103
|
- lib/bluepill/triggers/flapping.rb
|
|
95
104
|
- lib/bluepill/units.rb
|
|
@@ -99,12 +108,16 @@ files:
|
|
|
99
108
|
- lib/bluepill/version.rb
|
|
100
109
|
- sig/bluepill.rbs
|
|
101
110
|
- sig/bluepill/application.rbs
|
|
111
|
+
- sig/bluepill/attributes.rbs
|
|
102
112
|
- sig/bluepill/checks.rbs
|
|
103
|
-
- sig/bluepill/deprecation.rbs
|
|
104
113
|
- sig/bluepill/dsl.rbs
|
|
114
|
+
- sig/bluepill/errors.rbs
|
|
105
115
|
- sig/bluepill/logger.rbs
|
|
106
116
|
- sig/bluepill/process.rbs
|
|
117
|
+
- sig/bluepill/process_commands.rbs
|
|
118
|
+
- sig/bluepill/stop_signals.rbs
|
|
107
119
|
- sig/bluepill/system.rbs
|
|
120
|
+
- sig/bluepill/version.rbs
|
|
108
121
|
- sig/manifest.yaml
|
|
109
122
|
homepage: https://github.com/bluepill-rb/bluepill
|
|
110
123
|
licenses:
|
|
@@ -121,7 +134,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
121
134
|
requirements:
|
|
122
135
|
- - ">="
|
|
123
136
|
- !ruby/object:Gem::Version
|
|
124
|
-
version: '
|
|
137
|
+
version: '3.0'
|
|
125
138
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
139
|
requirements:
|
|
127
140
|
- - ">="
|
|
@@ -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
|
data/lib/bluepill/deprecation.rb
DELETED
|
@@ -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"
|