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
|
@@ -12,15 +12,15 @@ module Bluepill
|
|
|
12
12
|
class BelowThreshold < ProcessCondition
|
|
13
13
|
# Create the check
|
|
14
14
|
#
|
|
15
|
-
# @param [
|
|
16
|
-
#
|
|
15
|
+
# @param [Numeric] below the limit
|
|
16
|
+
# @param [Hash{Symbol => Object}] options the check's other options
|
|
17
17
|
#
|
|
18
18
|
# @return [void]
|
|
19
19
|
#
|
|
20
20
|
# @api private
|
|
21
|
-
def initialize(options
|
|
22
|
-
super
|
|
23
|
-
@below =
|
|
21
|
+
def initialize(below:, **options)
|
|
22
|
+
super(**options)
|
|
23
|
+
@below = below
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
# Return whether a value is below the limit
|
|
@@ -30,9 +30,7 @@ module Bluepill
|
|
|
30
30
|
# @return [Boolean] true when it's below the limit
|
|
31
31
|
#
|
|
32
32
|
# @api private
|
|
33
|
-
def check?(value)
|
|
34
|
-
value < @below
|
|
35
|
-
end
|
|
33
|
+
def check?(value) = value < @below
|
|
36
34
|
end
|
|
37
35
|
end
|
|
38
36
|
end
|
|
@@ -21,10 +21,7 @@ module Bluepill
|
|
|
21
21
|
# @return [Float] the percentage, or 0.0 for a process ps doesn't list
|
|
22
22
|
#
|
|
23
23
|
# @api private
|
|
24
|
-
def run(pid, include_children)
|
|
25
|
-
# third col in the ps axu output
|
|
26
|
-
System.cpu_usage(pid, include_children).to_f
|
|
27
|
-
end
|
|
24
|
+
def run(pid, include_children) = System.cpu_usage(pid, include_children).to_f
|
|
28
25
|
end
|
|
29
26
|
end
|
|
30
27
|
end
|
|
@@ -15,16 +15,17 @@ module Bluepill
|
|
|
15
15
|
class FileTime < BelowThreshold
|
|
16
16
|
# Create the check
|
|
17
17
|
#
|
|
18
|
-
# @param [
|
|
19
|
-
#
|
|
20
|
-
#
|
|
18
|
+
# @param [String] filename the file
|
|
19
|
+
# @param [Numeric] below the longest the file may go without changing,
|
|
20
|
+
# in seconds
|
|
21
|
+
# @param [Hash{Symbol => Object}] options the check's other options
|
|
21
22
|
#
|
|
22
23
|
# @return [void]
|
|
23
24
|
#
|
|
24
25
|
# @api private
|
|
25
|
-
def initialize(
|
|
26
|
-
super
|
|
27
|
-
@filename =
|
|
26
|
+
def initialize(filename:, below:, **options)
|
|
27
|
+
super(below: below, **options)
|
|
28
|
+
@filename = filename
|
|
28
29
|
end
|
|
29
30
|
|
|
30
31
|
# Read the seconds since the file changed
|
|
@@ -50,9 +51,7 @@ module Bluepill
|
|
|
50
51
|
# for a missing file or an error
|
|
51
52
|
#
|
|
52
53
|
# @api private
|
|
53
|
-
def check?(value)
|
|
54
|
-
value.is_a?(Numeric) && super
|
|
55
|
-
end
|
|
54
|
+
def check?(value) = value.is_a?(Numeric) && super
|
|
56
55
|
end
|
|
57
56
|
end
|
|
58
57
|
end
|
|
@@ -10,25 +10,32 @@ module Bluepill
|
|
|
10
10
|
# A config names it `checks :http`, with url: the URL to get, kind: the
|
|
11
11
|
# response it should be (a Net::HTTP class name such as :success or
|
|
12
12
|
# :ok, or a status code such as 200, :success by default), pattern: a
|
|
13
|
-
# Regexp its body should match, timeout: (or open_timeout: and
|
|
14
|
-
# read_timeout:) in seconds, 5 by default
|
|
15
|
-
#
|
|
16
|
-
# default.
|
|
13
|
+
# Regexp its body should match, and timeout: (or open_timeout: and
|
|
14
|
+
# read_timeout:) in seconds, 5 by default. An https URL's certificate
|
|
15
|
+
# must be valid, unless verify_ssl: is false, as for a self-signed one.
|
|
17
16
|
#
|
|
18
17
|
# @example
|
|
19
18
|
# process.checks :http, url: 'http://localhost:4567/', kind: :success, pattern: /html/, timeout: 3.seconds
|
|
20
|
-
#
|
|
19
|
+
#
|
|
20
|
+
# @example A server with a self-signed certificate
|
|
21
|
+
# process.checks :http, url: 'https://localhost:4443/', verify_ssl: false
|
|
21
22
|
#
|
|
22
23
|
# @api private
|
|
23
24
|
class Http < ProcessCondition
|
|
24
25
|
# Create the check
|
|
25
26
|
#
|
|
26
|
-
#
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
#
|
|
30
|
-
#
|
|
31
|
-
#
|
|
27
|
+
# @param [String] url the URL to get
|
|
28
|
+
# @param [Integer, String, Symbol, nil] kind the response it expects,
|
|
29
|
+
# as a status code, such as 200, or a Net::HTTP class name, such as
|
|
30
|
+
# :success, the default
|
|
31
|
+
# @param [Regexp, nil] pattern what the body must match, if anything
|
|
32
|
+
# @param [Numeric, String] timeout the seconds to wait to connect and
|
|
33
|
+
# to read, unless open_timeout or read_timeout is given
|
|
34
|
+
# @param [Numeric, String] open_timeout the seconds to wait to connect
|
|
35
|
+
# @param [Numeric, String] read_timeout the seconds to wait to read
|
|
36
|
+
# @param [Boolean] verify_ssl whether an https URL's certificate must
|
|
37
|
+
# be valid, true by default
|
|
38
|
+
# @param [Hash{Symbol => Object}] options the check's other options
|
|
32
39
|
#
|
|
33
40
|
# @return [void]
|
|
34
41
|
#
|
|
@@ -37,21 +44,18 @@ module Bluepill
|
|
|
37
44
|
# @raise [NameError] for a kind that names no Net::HTTP response
|
|
38
45
|
#
|
|
39
46
|
# @api private
|
|
40
|
-
def initialize(
|
|
41
|
-
super
|
|
42
|
-
@
|
|
43
|
-
@
|
|
44
|
-
@
|
|
45
|
-
@
|
|
46
|
-
@
|
|
47
|
-
@
|
|
48
|
-
warn_unverified(options)
|
|
47
|
+
def initialize(url:, kind: nil, pattern: nil, timeout: 5, open_timeout: timeout, read_timeout: timeout, verify_ssl: true, **options)
|
|
48
|
+
super(**options)
|
|
49
|
+
@verify_ssl = verify_ssl
|
|
50
|
+
@uri = URI.parse(url) #: URI::HTTP
|
|
51
|
+
@kind = response_class(kind)
|
|
52
|
+
@pattern = pattern
|
|
53
|
+
@open_timeout = open_timeout.to_i
|
|
54
|
+
@read_timeout = read_timeout.to_i
|
|
49
55
|
end
|
|
50
56
|
|
|
51
57
|
# Get the URL
|
|
52
58
|
#
|
|
53
|
-
# HTTPS is checked without verifying the certificate.
|
|
54
|
-
#
|
|
55
59
|
# @param [Integer, nil] _pid the process's pid
|
|
56
60
|
# @param [Boolean] _include_children whether to include its children
|
|
57
61
|
#
|
|
@@ -60,12 +64,7 @@ module Bluepill
|
|
|
60
64
|
#
|
|
61
65
|
# @api private
|
|
62
66
|
def run(_pid, _include_children)
|
|
63
|
-
|
|
64
|
-
hide_net_http_bug do
|
|
65
|
-
session.start do |http|
|
|
66
|
-
http.get(@uri.request_uri)
|
|
67
|
-
end
|
|
68
|
-
end
|
|
67
|
+
new_session.start { |http| http.get(@uri.request_uri) }
|
|
69
68
|
rescue => e
|
|
70
69
|
e
|
|
71
70
|
end
|
|
@@ -90,21 +89,6 @@ module Bluepill
|
|
|
90
89
|
|
|
91
90
|
private
|
|
92
91
|
|
|
93
|
-
# Warn about an https check that doesn't set verify_ssl
|
|
94
|
-
#
|
|
95
|
-
# @param [Hash{Symbol => Object}] options the check's options
|
|
96
|
-
#
|
|
97
|
-
# @return [void]
|
|
98
|
-
#
|
|
99
|
-
# @api private
|
|
100
|
-
def warn_unverified(options)
|
|
101
|
-
return unless @uri.scheme.eql?("https") && !options.key?(:verify_ssl)
|
|
102
|
-
|
|
103
|
-
Deprecation.warn("bluepill 0.3.0 verifies the certificate of an https check, so the check of #{@uri} fails " \
|
|
104
|
-
"if its certificate is self-signed or otherwise invalid. Add verify_ssl: true to verify it now, " \
|
|
105
|
-
"or verify_ssl: false to keep checking it without verification.")
|
|
106
|
-
end
|
|
107
|
-
|
|
108
92
|
# Return the Net::HTTPResponse class of a kind of response
|
|
109
93
|
#
|
|
110
94
|
# @param [Integer, String, Symbol, nil] kind a status code, such as
|
|
@@ -131,7 +115,7 @@ module Bluepill
|
|
|
131
115
|
|
|
132
116
|
# Return a session with the URL's host, set up to get the URL
|
|
133
117
|
#
|
|
134
|
-
# HTTPS
|
|
118
|
+
# HTTPS verifies the server's certificate, unless verify_ssl is false.
|
|
135
119
|
#
|
|
136
120
|
# @return [Net::HTTP] the session, not started yet
|
|
137
121
|
#
|
|
@@ -148,29 +132,6 @@ module Bluepill
|
|
|
148
132
|
session.read_timeout = @read_timeout
|
|
149
133
|
session
|
|
150
134
|
end
|
|
151
|
-
|
|
152
|
-
# Run the block, raising a refused connection as one
|
|
153
|
-
#
|
|
154
|
-
# Net::HTTP raises NoMethodError (closed? for nil) when it can't
|
|
155
|
-
# connect, so this raises Errno::ECONNREFUSED instead.
|
|
156
|
-
#
|
|
157
|
-
# @yield the request
|
|
158
|
-
# @yieldreturn [Object] the response
|
|
159
|
-
#
|
|
160
|
-
# @return [Object] what the block returns
|
|
161
|
-
#
|
|
162
|
-
# @raise [Errno::ECONNREFUSED] when the connection was refused
|
|
163
|
-
#
|
|
164
|
-
# @api private
|
|
165
|
-
def hide_net_http_bug
|
|
166
|
-
yield
|
|
167
|
-
rescue NoMethodError => e
|
|
168
|
-
# Ruby 3.4 changed the wording of this error
|
|
169
|
-
message = e.to_s
|
|
170
|
-
raise(Errno::ECONNREFUSED, "Connection refused attempting to contact #{@uri.scheme}://#{@uri.host}:#{@uri.port}") if message.include?("undefined method `closed?' for nil:NilClass") || message.include?("undefined method 'closed?' for nil")
|
|
171
|
-
|
|
172
|
-
raise
|
|
173
|
-
end
|
|
174
135
|
end
|
|
175
136
|
end
|
|
176
137
|
end
|
|
@@ -13,67 +13,29 @@ module Bluepill
|
|
|
13
13
|
#
|
|
14
14
|
# @api private
|
|
15
15
|
class MemUsage < BelowThreshold
|
|
16
|
-
# The bytes in a megabyte, from which a value shows in megabytes
|
|
17
|
-
#
|
|
18
|
-
# @api private
|
|
19
|
-
MB = (1024**2) #: Integer
|
|
20
|
-
|
|
21
|
-
# How a value shows in the history: a number and its unit
|
|
22
|
-
#
|
|
23
|
-
# @api private
|
|
24
|
-
FORMAT_STR = "%d%s"
|
|
25
|
-
|
|
26
|
-
# The unit of a value that shows in megabytes
|
|
27
|
-
#
|
|
28
|
-
# @api private
|
|
29
|
-
MB_LABEL = "MB"
|
|
30
|
-
|
|
31
|
-
# The unit of a value that shows in kilobytes
|
|
32
|
-
#
|
|
33
|
-
# @api private
|
|
34
|
-
KB_LABEL = "KB"
|
|
35
|
-
|
|
36
16
|
# Read the process's memory usage from the tick's ps table
|
|
37
17
|
#
|
|
38
18
|
# @param [Integer, nil] pid the process's pid
|
|
39
19
|
# @param [Boolean] include_children whether to add its children's usage
|
|
40
20
|
#
|
|
41
|
-
# @return [Float] the usage in
|
|
42
|
-
#
|
|
43
|
-
#
|
|
44
|
-
# @api private
|
|
45
|
-
def run(pid, include_children)
|
|
46
|
-
# rss is on the 5th col
|
|
47
|
-
System.memory_usage(pid, include_children).to_f
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
# Return whether the usage is below the limit
|
|
51
|
-
#
|
|
52
|
-
# A limit that can't be compared counts as fine.
|
|
53
|
-
#
|
|
54
|
-
# @param [Float] value the kilobytes run read
|
|
55
|
-
#
|
|
56
|
-
# @return [Boolean] true when it's below the limit
|
|
21
|
+
# @return [Float] the usage in bytes, or 0.0 for a process ps doesn't
|
|
22
|
+
# list
|
|
57
23
|
#
|
|
58
24
|
# @api private
|
|
59
|
-
def
|
|
60
|
-
value * 1024 < @below
|
|
61
|
-
rescue
|
|
62
|
-
true
|
|
63
|
-
end
|
|
25
|
+
def run(pid, include_children) = System.memory_usage(pid, include_children).to_f * Units::KILOBYTE
|
|
64
26
|
|
|
65
27
|
# Format the usage in kilobytes, or in megabytes from a megabyte up
|
|
66
28
|
#
|
|
67
|
-
# @param [Float] value the
|
|
29
|
+
# @param [Float] value the bytes run read
|
|
68
30
|
#
|
|
69
31
|
# @return [String] the usage and its unit, such as "312KB" or "250MB"
|
|
70
32
|
#
|
|
71
33
|
# @api private
|
|
72
34
|
def format_value(value)
|
|
73
|
-
if value
|
|
74
|
-
format(
|
|
35
|
+
if value >= Units::MEGABYTE
|
|
36
|
+
format("%dMB", (value / Units::MEGABYTE).round)
|
|
75
37
|
else
|
|
76
|
-
format(
|
|
38
|
+
format("%dKB", value / Units::KILOBYTE)
|
|
77
39
|
end
|
|
78
40
|
end
|
|
79
41
|
end
|
|
@@ -7,10 +7,30 @@ module Bluepill
|
|
|
7
7
|
# A ConditionWatch runs the condition every so often. The condition reads
|
|
8
8
|
# a value (run), says whether the value is fine (check), and formats it
|
|
9
9
|
# for the watch's history (format_value). Subclasses implement run and
|
|
10
|
-
# check
|
|
10
|
+
# check?, and add themselves to CheckRegistry by their underscored
|
|
11
|
+
# name, in whatever module they're defined.
|
|
11
12
|
#
|
|
12
13
|
# @api private
|
|
13
14
|
class ProcessCondition
|
|
15
|
+
# The methods a subclass must define
|
|
16
|
+
#
|
|
17
|
+
# @api private
|
|
18
|
+
REQUIRED_METHODS = %i[run check?].freeze
|
|
19
|
+
|
|
20
|
+
# Add a subclass to the checks a config can name
|
|
21
|
+
#
|
|
22
|
+
# A config names it by its underscored name, such as :mem_usage.
|
|
23
|
+
#
|
|
24
|
+
# @param [Class] klass the subclass
|
|
25
|
+
#
|
|
26
|
+
# @return [void]
|
|
27
|
+
#
|
|
28
|
+
# @api private
|
|
29
|
+
def self.inherited(klass)
|
|
30
|
+
super
|
|
31
|
+
CheckRegistry.add(klass, ProcessCondition, REQUIRED_METHODS)
|
|
32
|
+
end
|
|
33
|
+
|
|
14
34
|
# Return the logger the condition can write to
|
|
15
35
|
#
|
|
16
36
|
# It's the watch's logger, so lines carry the app's and the process's
|
|
@@ -25,33 +45,17 @@ module Bluepill
|
|
|
25
45
|
# @api public
|
|
26
46
|
attr_reader :logger
|
|
27
47
|
|
|
28
|
-
# Set the logger the condition writes to
|
|
29
|
-
#
|
|
30
|
-
# The watch sets it. Bluepill 0.3.0 removes it, so it warns when
|
|
31
|
-
# code outside bluepill calls it.
|
|
32
|
-
#
|
|
33
|
-
# @param [Logger, nil] logger the process's logger
|
|
34
|
-
#
|
|
35
|
-
# @return [void]
|
|
36
|
-
#
|
|
37
|
-
# @api private
|
|
38
|
-
def logger=(logger)
|
|
39
|
-
locations = caller_locations(0, 2) #: Array[Thread::Backtrace::Location]
|
|
40
|
-
Deprecation.check_logger_writer(self, locations.last)
|
|
41
|
-
@logger = logger
|
|
42
|
-
end
|
|
43
|
-
|
|
44
48
|
# Create a condition with the options a config gave its check
|
|
45
49
|
#
|
|
46
|
-
# @param [
|
|
47
|
-
# below: 100.megabytes, and the watch's logger as logger:
|
|
50
|
+
# @param [Logger, nil] logger the watch's logger
|
|
48
51
|
#
|
|
49
52
|
# @return [void]
|
|
50
53
|
#
|
|
54
|
+
# @raise [ArgumentError] for an option that no condition takes
|
|
55
|
+
#
|
|
51
56
|
# @api private
|
|
52
|
-
def initialize(
|
|
53
|
-
@logger =
|
|
54
|
-
@options = options
|
|
57
|
+
def initialize(logger: nil)
|
|
58
|
+
@logger = logger
|
|
55
59
|
end
|
|
56
60
|
|
|
57
61
|
# Read the value to check from the process
|
|
@@ -64,28 +68,10 @@ module Bluepill
|
|
|
64
68
|
# @raise [RuntimeError] unless a subclass implements it
|
|
65
69
|
#
|
|
66
70
|
# @api private
|
|
67
|
-
def run(_pid, _include_children)
|
|
68
|
-
raise "Implement in subclass!"
|
|
69
|
-
end
|
|
71
|
+
def run(_pid, _include_children) = raise("Implement in subclass!")
|
|
70
72
|
|
|
71
73
|
# Return whether a value is fine
|
|
72
74
|
#
|
|
73
|
-
# A subclass implements it. This one calls check, so a custom check
|
|
74
|
-
# written for bluepill 0.1, which defines check, still works.
|
|
75
|
-
#
|
|
76
|
-
# @param [Object] value what run read
|
|
77
|
-
#
|
|
78
|
-
# @return [Boolean] true when the value is fine, false when it's not
|
|
79
|
-
#
|
|
80
|
-
# @raise [RuntimeError] unless a subclass implements check? or check
|
|
81
|
-
#
|
|
82
|
-
# @api private
|
|
83
|
-
def check?(value)
|
|
84
|
-
check(value)
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
# Return whether a value is fine, as bluepill 0.1 named check?
|
|
88
|
-
#
|
|
89
75
|
# @param [Object] _value what run read
|
|
90
76
|
#
|
|
91
77
|
# @return [Boolean] true when the value is fine, false when it's not
|
|
@@ -93,9 +79,7 @@ module Bluepill
|
|
|
93
79
|
# @raise [RuntimeError] unless a subclass implements it
|
|
94
80
|
#
|
|
95
81
|
# @api private
|
|
96
|
-
def check(_value)
|
|
97
|
-
raise "Implement in subclass!"
|
|
98
|
-
end
|
|
82
|
+
def check?(_value) = raise("Implement in subclass!")
|
|
99
83
|
|
|
100
84
|
# Format a value for the watch's history and log
|
|
101
85
|
#
|
|
@@ -105,9 +89,7 @@ module Bluepill
|
|
|
105
89
|
# value itself
|
|
106
90
|
#
|
|
107
91
|
# @api private
|
|
108
|
-
def format_value(value)
|
|
109
|
-
value
|
|
110
|
-
end
|
|
92
|
+
def format_value(value) = value
|
|
111
93
|
end
|
|
112
94
|
end
|
|
113
95
|
end
|
|
@@ -22,9 +22,7 @@ module Bluepill
|
|
|
22
22
|
# doesn't list
|
|
23
23
|
#
|
|
24
24
|
# @api private
|
|
25
|
-
def run(pid, _include_children)
|
|
26
|
-
System.command(pid)
|
|
27
|
-
end
|
|
25
|
+
def run(pid, _include_children) = System.command(pid)
|
|
28
26
|
|
|
29
27
|
# Return whether the process isn't a zombie
|
|
30
28
|
#
|
|
@@ -33,9 +31,7 @@ module Bluepill
|
|
|
33
31
|
# @return [Boolean] true unless the command line says <defunct>
|
|
34
32
|
#
|
|
35
33
|
# @api private
|
|
36
|
-
def check?(value)
|
|
37
|
-
!value&.match?(/<defunct>/)
|
|
38
|
-
end
|
|
34
|
+
def check?(value) = !value&.match?(/<defunct>/)
|
|
39
35
|
end
|
|
40
36
|
end
|
|
41
37
|
end
|
|
@@ -1,29 +1,20 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "bluepill/check_registry"
|
|
4
|
+
|
|
3
5
|
module Bluepill
|
|
4
6
|
# The checks a process can run, named in a config by their underscored
|
|
5
7
|
# class name, such as `checks :mem_usage`
|
|
6
8
|
#
|
|
9
|
+
# CheckRegistry finds them by that name.
|
|
10
|
+
#
|
|
7
11
|
# @api private
|
|
8
12
|
module ProcessConditions
|
|
9
|
-
# Return the check class a config names
|
|
10
|
-
#
|
|
11
|
-
# @param [Symbol, String] name the check's underscored name, such as
|
|
12
|
-
# :mem_usage
|
|
13
|
-
#
|
|
14
|
-
# @return [Class] the ProcessCondition subclass, such as MemUsage
|
|
15
|
-
#
|
|
16
|
-
# @raise [NameError] when no check has that name
|
|
17
|
-
#
|
|
18
|
-
# @api private
|
|
19
|
-
def self.[](name)
|
|
20
|
-
const_get(Util.camelize(name))
|
|
21
|
-
end
|
|
22
13
|
end
|
|
23
14
|
end
|
|
24
15
|
|
|
25
16
|
require "bluepill/process_conditions/process_condition"
|
|
26
17
|
require "bluepill/process_conditions/below_threshold"
|
|
27
|
-
Dir["#{File.dirname(__FILE__)}/process_conditions/*.rb"].
|
|
18
|
+
Dir["#{File.dirname(__FILE__)}/process_conditions/*.rb"].each do |pc|
|
|
28
19
|
require pc
|
|
29
20
|
end
|
|
@@ -6,77 +6,29 @@ module Bluepill
|
|
|
6
6
|
#
|
|
7
7
|
# Before bluepill starts a process, it kills the processes and process
|
|
8
8
|
# groups its journals list that are still the ones bluepill journaled,
|
|
9
|
-
# and then clears the journals. ProcessJournal extends it
|
|
9
|
+
# and then clears the journals. ProcessJournal extends it, and a
|
|
10
|
+
# Journal calls it.
|
|
10
11
|
#
|
|
11
12
|
# @api private
|
|
12
13
|
module Cleanup
|
|
13
|
-
# Kill the processes and process groups that a process's journals list
|
|
14
|
-
#
|
|
15
|
-
# @param [String] journal_name the process's name
|
|
16
|
-
#
|
|
17
|
-
# @return [void]
|
|
18
|
-
#
|
|
19
|
-
# @api private
|
|
20
|
-
def kill_all_from_journal(journal_name)
|
|
21
|
-
kill_all_pids_from_journal(journal_name)
|
|
22
|
-
kill_all_pgids_from_journal(journal_name)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
# Kill the process groups that a process's journals list
|
|
26
|
-
#
|
|
27
|
-
# That's the app's journal, and the one that bluepill 0.1 and earlier
|
|
28
|
-
# shared between apps.
|
|
29
|
-
#
|
|
30
|
-
# @param [String] journal_name the process's name
|
|
31
|
-
#
|
|
32
|
-
# @return [void]
|
|
33
|
-
#
|
|
34
|
-
# @api private
|
|
35
|
-
def kill_all_pgids_from_journal(journal_name)
|
|
36
|
-
kill_all_ids_from_journal(PGID, journal_name)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
# Kill the processes that a process's journals list
|
|
40
|
-
#
|
|
41
|
-
# That's the app's journal, and the one that bluepill 0.1 and earlier
|
|
42
|
-
# shared between apps.
|
|
43
|
-
#
|
|
44
|
-
# @param [String] journal_name the process's name
|
|
45
|
-
#
|
|
46
|
-
# @return [void]
|
|
47
|
-
#
|
|
48
|
-
# @api private
|
|
49
|
-
def kill_all_pids_from_journal(journal_name)
|
|
50
|
-
kill_all_ids_from_journal(PID, journal_name)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
14
|
# Kill the ids that one kind of a process's journals list
|
|
54
15
|
#
|
|
55
16
|
# That's the app's journal, and the one that bluepill 0.1 and earlier
|
|
56
17
|
# shared between apps.
|
|
57
18
|
#
|
|
58
19
|
# @param [Kind] kind PID or PGID
|
|
59
|
-
# @param [
|
|
20
|
+
# @param [#to_s] journal_name the process's name
|
|
60
21
|
#
|
|
61
22
|
# @return [void]
|
|
62
23
|
#
|
|
63
24
|
# @api private
|
|
64
|
-
def
|
|
25
|
+
def kill_all(kind, journal_name)
|
|
65
26
|
journal_dirs.each do |dir|
|
|
66
|
-
filename =
|
|
27
|
+
filename = kind.filename(dir, journal_name)
|
|
67
28
|
kill_all_from_journal_file(filename, journal_ids(kind, filename), kind)
|
|
68
29
|
end
|
|
69
30
|
end
|
|
70
31
|
|
|
71
|
-
# Return the directories a process's journals can be in
|
|
72
|
-
#
|
|
73
|
-
# @return [Array<String>] the app's, and then the one before 0.2
|
|
74
|
-
#
|
|
75
|
-
# @api private
|
|
76
|
-
def journal_dirs
|
|
77
|
-
[journal_base_dir, legacy_journal_dir]
|
|
78
|
-
end
|
|
79
|
-
|
|
80
32
|
# Kill the ids a journal lists, and then delete the journal
|
|
81
33
|
#
|
|
82
34
|
# Only kills the ids that still belong to what bluepill journaled (see
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Bluepill
|
|
4
|
+
module ProcessJournal
|
|
5
|
+
# Where the journals are, and the logger they write to
|
|
6
|
+
#
|
|
7
|
+
# Only the first app and logger are kept, since one daemon monitors one
|
|
8
|
+
# app. ProcessJournal extends it.
|
|
9
|
+
#
|
|
10
|
+
# @api private
|
|
11
|
+
module Config
|
|
12
|
+
# Return the logger the journal writes to
|
|
13
|
+
#
|
|
14
|
+
# @return [Logger] the first logger that was set
|
|
15
|
+
#
|
|
16
|
+
# @api private
|
|
17
|
+
attr_reader :logger
|
|
18
|
+
|
|
19
|
+
# Return the directory the app's journals are in
|
|
20
|
+
#
|
|
21
|
+
# @return [String] the app's directory in the journals directory
|
|
22
|
+
#
|
|
23
|
+
# @api private
|
|
24
|
+
attr_reader :journal_base_dir
|
|
25
|
+
|
|
26
|
+
# Return the directory every app's journals were in before 0.2
|
|
27
|
+
#
|
|
28
|
+
# @return [String] the journals directory under bluepill's base dir
|
|
29
|
+
#
|
|
30
|
+
# @api private
|
|
31
|
+
attr_reader :legacy_journal_dir
|
|
32
|
+
|
|
33
|
+
# Set the logger the journal writes to, unless it already has one
|
|
34
|
+
#
|
|
35
|
+
# @param [Logger] new_logger the logger to use
|
|
36
|
+
#
|
|
37
|
+
# @return [Logger] the logger
|
|
38
|
+
#
|
|
39
|
+
# @api private
|
|
40
|
+
def logger=(new_logger)
|
|
41
|
+
@logger ||= new_logger
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Set the app's journal directory from bluepill's base dir, and create it
|
|
45
|
+
#
|
|
46
|
+
# Only the first base dir and app are kept. The directories are made
|
|
47
|
+
# world-writable so processes that run as other users can lock their
|
|
48
|
+
# journals.
|
|
49
|
+
#
|
|
50
|
+
# @param [String] base_dir bluepill's base directory
|
|
51
|
+
# @param [#to_s] app_name the app's name
|
|
52
|
+
#
|
|
53
|
+
# @return [void]
|
|
54
|
+
#
|
|
55
|
+
# @api private
|
|
56
|
+
def setup(base_dir, app_name)
|
|
57
|
+
@legacy_journal_dir ||= BaseDirectory.new(base_dir).journals_dir
|
|
58
|
+
@journal_base_dir ||= File.join(@legacy_journal_dir, app_name.to_s)
|
|
59
|
+
journal_dirs.each do |dir|
|
|
60
|
+
FileUtils.mkdir_p(dir)
|
|
61
|
+
FileUtils.chmod(0o777, dir)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Return the directories a process's journals can be in
|
|
66
|
+
#
|
|
67
|
+
# @return [Array<String>] the app's, and then the one before 0.2
|
|
68
|
+
#
|
|
69
|
+
# @api private
|
|
70
|
+
def journal_dirs = [journal_base_dir, legacy_journal_dir]
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|