bluepill 0.2.7 → 0.2.9
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 +46 -1
- data/README.md +8 -6
- data/lib/bluepill/application/lifecycle.rb +3 -1
- data/lib/bluepill/application/previous_daemon.rb +6 -4
- data/lib/bluepill/application.rb +19 -3
- data/lib/bluepill/condition_watch.rb +26 -23
- data/lib/bluepill/controller.rb +22 -9
- data/lib/bluepill/deprecation/custom_checks.rb +193 -0
- data/lib/bluepill/deprecation/dsl.rb +141 -0
- data/lib/bluepill/deprecation/options.rb +140 -0
- data/lib/bluepill/deprecation.rb +92 -0
- data/lib/bluepill/dsl/app_proxy.rb +8 -1
- data/lib/bluepill/dsl/process_factory/children.rb +26 -0
- data/lib/bluepill/dsl/process_factory.rb +18 -1
- data/lib/bluepill/dsl/process_proxy.rb +18 -8
- data/lib/bluepill/dsl.rb +11 -3
- data/lib/bluepill/process/transition_callbacks.rb +4 -7
- data/lib/bluepill/process.rb +20 -8
- data/lib/bluepill/process_conditions/http.rb +28 -4
- data/lib/bluepill/process_conditions/process_condition.rb +17 -1
- data/lib/bluepill/trigger.rb +44 -3
- data/lib/bluepill/util/log_error.rb +28 -0
- data/lib/bluepill/version.rb +7 -7
- data/lib/bluepill.rb +1 -0
- data/sig/bluepill/application.rbs +7 -1
- data/sig/bluepill/checks.rbs +15 -2
- data/sig/bluepill/deprecation.rbs +87 -0
- data/sig/bluepill/dsl.rbs +8 -2
- data/sig/bluepill/process.rbs +4 -0
- data/sig/bluepill.rbs +4 -1
- metadata +7 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f99d17a71de30a8740c305e79371a5a41b8563291883ab151fd8dd09b1a043f6
|
|
4
|
+
data.tar.gz: 568d20ca8eb2e480a3d54047e2d71ec6982b7f46653cffe8ca668252cd57122e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0b8fcfe797993aaa1f5663e96b0a68028e1979181c2d2d5d36dc81ebaa44f8549c7c84d83f9598392d1f36740c8ffa1e89b710927045427ed3a945951e03135c
|
|
7
|
+
data.tar.gz: 40be778dcf5a90336923599c6bc9d9cb8485ee986d8da46ea0169c4264023383e3416a3296d133106391a9bdcc709e4c42cd498208c130ca9e486ab5335cddf6
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,49 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.2.9] - 2026-11-02
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- The `http` check's `verify_ssl:` option. Set it to true to verify an https server's certificate, which bluepill 0.3.0 does by default. It's off by default in 0.2.9, so a check of a server with a self-signed certificate keeps passing.
|
|
15
|
+
- A custom check or trigger gets its options as keyword arguments, so one can name them, as in `def initialize(path:, below:, **options)` and `super(**options)`, as bluepill 0.3.0 needs. One that takes them as a Hash, as in `def initialize(options = {})`, still gets the Hash.
|
|
16
|
+
|
|
17
|
+
### Deprecated
|
|
18
|
+
|
|
19
|
+
Bluepill 0.2.9 warns, once each, about what will break in 0.3.0. Each warning starts with `DEPRECATION:` and says what to change, and `bluepill load` prints it, before the daemon starts, and logs it at `warning`. A pill file that loads without any works with 0.3.0.
|
|
20
|
+
|
|
21
|
+
- Running on Ruby 2.7. Bluepill 0.3.0 needs Ruby 3.0 or newer, or JRuby 9.4 or newer.
|
|
22
|
+
- An application option that bluepill 0.3.0 doesn't take, such as a misspelled `log_flie:`, which 0.2 ignores. Bluepill 0.3.0 fails the config.
|
|
23
|
+
- Options kept in a Hash and passed to `Bluepill.application` or `checks` without `**`, as in `process.checks :mem_usage, options`, on Ruby 3.0 or newer. Bluepill 0.3.0 takes them only as keyword arguments, so write `process.checks :mem_usage, **options`. Ruby 2.7 passes such a Hash as keywords, so bluepill can't tell there.
|
|
24
|
+
- An https `http` check without `verify_ssl:`. Bluepill 0.3.0 verifies the server's certificate by default, so set `verify_ssl: false` to keep checking a server with a self-signed certificate.
|
|
25
|
+
- A daemon older than 0.2.9, which the CLI of bluepill 0.3.0 says is out of date. Run `bluepill load` again after upgrading, so the daemon runs the same version as the CLI.
|
|
26
|
+
- A custom check or trigger whose `initialize` takes its options as a Hash, as in `def initialize(options = {})`. Bluepill 0.3.0 passes them as keyword arguments, so name them, as in `def initialize(path:, below:, **options)`, and call `super(**options)`.
|
|
27
|
+
- A custom check that defines `check` instead of `check?`, or that doesn't define `run` and `check?`, and a custom trigger that doesn't define `notify`. Bluepill 0.3.0 fails the config.
|
|
28
|
+
- A custom check or trigger whose `initialize` doesn't call `super`. Bluepill 0.3.0 gives it its logger only through `super`.
|
|
29
|
+
- Calling `logger=` on a check or trigger from outside bluepill. Bluepill 0.3.0 removes it.
|
|
30
|
+
- A custom trigger that dispatches an event as a String, such as `dispatch!("start")`. Bluepill 0.3.0 takes only Symbols.
|
|
31
|
+
- An option of a built-in check or trigger that bluepill 0.3.0 doesn't take, such as a misspelled `evry:`, or `within:` on an `http` check, which 0.2 ignores, and a check without an option that 0.3.0 needs: `below:` for `mem_usage`, `cpu_usage` and `running_time`, and `filename:` and `below:` for `file_time`. Bluepill 0.3.0 fails the config.
|
|
32
|
+
- A `fires:` or `on_start_timeout` that isn't one of the Symbols `:start`, `:stop`, `:unmonitor` and `:restart`, such as `"stop"`. Bluepill 0.3.0 fails the config.
|
|
33
|
+
- Setting a process attribute with `name!` or `name value`, such as `process.daemonize!` or `process.start_command "cmd"`. Write `process.daemonize = true` and `process.start_command = "cmd"`.
|
|
34
|
+
- Setting `monitor_children` or `child_process_factory` in a process block, and `monitor_children` without a block. Bluepill 0.3.0 takes only `monitor_children` with a block.
|
|
35
|
+
- A `monitor_children` block that sets no `stop_command`. Bluepill 0.3.0 fails the config, where 0.2 exits the daemon when it first finds a child. To find it, and the mistakes in the children's checks, `bluepill load` runs the block once, as 0.3.0 does, for a child whose pid isn't known yet.
|
|
36
|
+
- Two checks of the same name in one process, such as two `:http` checks of different URLs. Bluepill 0.2 runs only the last, and 0.3.0 runs both.
|
|
37
|
+
- A custom check that subclasses `MemUsage`. Bluepill 0.3.0 gives its `run`, `check?` and `format_value` the memory usage in bytes, where 0.2 gives kilobytes.
|
|
38
|
+
- Bluepill 0.3.0 also changes some things that 0.2.9 can't warn about: options kept in a Hash and passed without `**` on Ruby 2.7, where Ruby can't tell them from keywords, a 0.3.0 `bluepill` command refuses every 0.2 daemon, so run `bluepill load` again after upgrading, a mistake that already fails a 0.2 config, such as a misspelled attribute, fails with a `Bluepill::ConfigError` and exit status 6, and reading an attribute that isn't set returns nil. Read 0.3.0's "Upgrading from 0.2" before upgrading.
|
|
39
|
+
- To check a `monitor_children` block, as 0.3.0 does, bluepill 0.2.9 runs it once when the pill file loads, for a child with no pid, besides once for each child it finds. A block that raises for that child gives no warning.
|
|
40
|
+
|
|
41
|
+
### Fixed
|
|
42
|
+
|
|
43
|
+
- An exception in a check or trigger no longer stops the daemon. It's logged, with its backtrace a line each, and the check is skipped until its next interval, so it doesn't count toward `times`. Before, it stopped the daemon with exit status 5, and the log showed the backtrace as one Array.
|
|
44
|
+
- The CLI's check that the daemon runs the same version of bluepill never failed: the daemon now answers with its version as a String. A daemon older than 0.2.9 can't say which version it runs, so the CLI talks to it as before, and a CLI older than 0.2.9 says that a 0.2.9 daemon is out of date.
|
|
45
|
+
- The daemon logs what stops it at `crit`, with its backtrace, since its stderr is `/dev/null`.
|
|
46
|
+
- `bluepill load` no longer prints an error when the daemon it replaces exits just before it's signaled.
|
|
47
|
+
|
|
48
|
+
### Security
|
|
49
|
+
|
|
50
|
+
- The `http` check can verify an https server's certificate, with `verify_ssl: true`. Without it, the check passes against any server that answers, whatever its certificate.
|
|
51
|
+
- `bluepill log` passes the log file's path and the pattern to `tail` and `grep` as the shell's arguments, so a path with spaces works, and a quote or `$(...)` in the path or in a process's name no longer runs as shell code.
|
|
52
|
+
|
|
10
53
|
## [0.2.7] - 2026-11-02
|
|
11
54
|
|
|
12
55
|
### Changed
|
|
@@ -99,6 +142,7 @@ To upgrade, install 0.2.0 and run `bluepill load` with the same pill file. It re
|
|
|
99
142
|
|
|
100
143
|
### Security
|
|
101
144
|
|
|
145
|
+
- The `http` check can verify an https server's certificate, with `verify_ssl: true`. Without it, the check passes against any server that answers, whatever its certificate.
|
|
102
146
|
- The daemon now runs only the commands that the CLI sends over its socket: `start`, `stop`, `restart`, `unmonitor`, `status`, `version` and `log_file`. Before, it called whatever method a line on the socket named, so anyone who could write to the socket could call any of the daemon's public methods, such as `instance_eval` with code of their own. The socket takes the daemon's umask, so with the usual umask of 022 only the daemon's own user could connect. Any other command now gets a `NoMethodError` back.
|
|
103
147
|
|
|
104
148
|
## [0.1.5] - 2026-11-01
|
|
@@ -852,7 +896,8 @@ Initial release.
|
|
|
852
896
|
- Added the `bluepill` CLI with the `load`, `status`, `start`, `stop`, `restart`, `unmonitor`, `quit` and `log` commands.
|
|
853
897
|
- Added syslog logging.
|
|
854
898
|
|
|
855
|
-
[unreleased]: https://github.com/bluepill-rb/bluepill/compare/v0.2.
|
|
899
|
+
[unreleased]: https://github.com/bluepill-rb/bluepill/compare/v0.2.9...HEAD
|
|
900
|
+
[0.2.9]: https://github.com/bluepill-rb/bluepill/compare/v0.2.7...v0.2.9
|
|
856
901
|
[0.2.7]: https://github.com/bluepill-rb/bluepill/compare/v0.2.5...v0.2.7
|
|
857
902
|
[0.2.5]: https://github.com/bluepill-rb/bluepill/compare/v0.2.3...v0.2.5
|
|
858
903
|
[0.2.3]: https://github.com/bluepill-rb/bluepill/compare/v0.2.1...v0.2.3
|
data/README.md
CHANGED
|
@@ -337,16 +337,16 @@ If a pill file loads ActiveSupport, for example by loading a Rails app, ActiveSu
|
|
|
337
337
|
|
|
338
338
|
### Custom checks
|
|
339
339
|
|
|
340
|
-
A check is a class in `Bluepill::ProcessConditions`, named after the check in camel case, so `checks :log_size` uses `LogSize`. Define it in the config file, before the application. It gets the check's options, except `every`, `times`, `fires`, and `include_children`, which bluepill handles. `run` reads a value, and `check?` returns whether the value is fine:
|
|
340
|
+
A check is a class in `Bluepill::ProcessConditions`, named after the check in camel case, so `checks :log_size` uses `LogSize`. Define it in the config file, before the application. It gets the check's options as keyword arguments, except `every`, `times`, `fires`, and `include_children`, which bluepill handles. `run` reads a value, and `check?` returns whether the value is fine:
|
|
341
341
|
|
|
342
342
|
```ruby
|
|
343
343
|
module Bluepill
|
|
344
344
|
module ProcessConditions
|
|
345
345
|
class LogSize < ProcessCondition
|
|
346
|
-
def initialize(
|
|
347
|
-
super
|
|
348
|
-
@path =
|
|
349
|
-
@below =
|
|
346
|
+
def initialize(path:, below:, **options)
|
|
347
|
+
super(**options)
|
|
348
|
+
@path = path
|
|
349
|
+
@below = below
|
|
350
350
|
end
|
|
351
351
|
|
|
352
352
|
def run(_pid, _include_children)
|
|
@@ -370,7 +370,9 @@ Bluepill.application("app_name") do |app|
|
|
|
370
370
|
end
|
|
371
371
|
```
|
|
372
372
|
|
|
373
|
-
`logger` writes to bluepill's log, with the app's and the process's names, like the built-in checks. It's set once `super` returns, so call `super` first in `initialize`.
|
|
373
|
+
`logger` writes to bluepill's log, with the app's and the process's names, like the built-in checks. It's set once `super` returns, so call `super` first in `initialize`.
|
|
374
|
+
|
|
375
|
+
A check whose `initialize` takes the options as a Hash, `def initialize(options = {})`, and one written for bluepill 0.1, which defines `check` instead of `check?`, still work, but bluepill 0.3.0 needs keywords and `check?`, so `bluepill load` warns about them. The keywords and `check?` work in 0.2.9 too.
|
|
374
376
|
|
|
375
377
|
### Commands Don't Run in a Shell
|
|
376
378
|
|
|
@@ -125,6 +125,8 @@ module Bluepill
|
|
|
125
125
|
|
|
126
126
|
# Create the logger and the pids directory
|
|
127
127
|
#
|
|
128
|
+
# The deprecation warnings go to the logger too.
|
|
129
|
+
#
|
|
128
130
|
# Bluepill opens its log file and creates its pids dir as the user that
|
|
129
131
|
# runs it. The uid and gid in the config only apply to its processes.
|
|
130
132
|
# It exits with status 5 if it can't.
|
|
@@ -133,7 +135,7 @@ module Bluepill
|
|
|
133
135
|
#
|
|
134
136
|
# @api private
|
|
135
137
|
def setup_logger_and_pids_dir
|
|
136
|
-
self.logger = ProcessJournal.logger = Logger.new(log_file: log_file, log_level: @log_level, stdout: foreground?).prefix_with(name)
|
|
138
|
+
self.logger = ProcessJournal.logger = Deprecation.logger = Logger.new(log_file: log_file, log_level: @log_level, stdout: foreground?).prefix_with(name)
|
|
137
139
|
setup_pids_dir
|
|
138
140
|
rescue SystemCallError => e
|
|
139
141
|
$stderr.puts("Failed to start bluepill: #{e}")
|
|
@@ -29,7 +29,7 @@ module Bluepill
|
|
|
29
29
|
# It exits with status 4 if signaling it fails, unless it's gone.
|
|
30
30
|
#
|
|
31
31
|
# @return [Integer, nil] the previous daemon's pid, or nil if it
|
|
32
|
-
# interrupted none
|
|
32
|
+
# interrupted none, such as when it has just exited
|
|
33
33
|
#
|
|
34
34
|
# @api private
|
|
35
35
|
def interrupt_previous_bluepill
|
|
@@ -40,10 +40,12 @@ module Bluepill
|
|
|
40
40
|
puts "Killing previous bluepilld[#{previous_pid}]"
|
|
41
41
|
::Process.kill(2, previous_pid)
|
|
42
42
|
previous_pid
|
|
43
|
+
rescue Errno::ESRCH
|
|
44
|
+
# It exited after previous_bluepill_pid saw it alive, so there's
|
|
45
|
+
# nothing to wait for
|
|
43
46
|
rescue => e
|
|
44
|
-
$stderr.puts "Encountered error trying to kill previous bluepill:"
|
|
45
|
-
|
|
46
|
-
exit(4) unless e.instance_of?(Errno::ESRCH)
|
|
47
|
+
$stderr.puts "Encountered error trying to kill previous bluepill:\n#{e.class}: #{e}"
|
|
48
|
+
exit(4)
|
|
47
49
|
end
|
|
48
50
|
|
|
49
51
|
# Return the pid of a previous daemon that's still running
|
data/lib/bluepill/application.rb
CHANGED
|
@@ -149,7 +149,8 @@ module Bluepill
|
|
|
149
149
|
# Start the daemon and monitor the application's processes
|
|
150
150
|
#
|
|
151
151
|
# It prints what went wrong, and exits with status 5, if the daemon
|
|
152
|
-
# fails to start.
|
|
152
|
+
# fails to start. Whatever stops it is also logged at crit, with its
|
|
153
|
+
# backtrace, since a daemon's stderr is /dev/null.
|
|
153
154
|
#
|
|
154
155
|
# @return [void]
|
|
155
156
|
#
|
|
@@ -157,6 +158,7 @@ module Bluepill
|
|
|
157
158
|
def load
|
|
158
159
|
start_server
|
|
159
160
|
rescue => e
|
|
161
|
+
log_crash(e)
|
|
160
162
|
$stderr.puts("Failed to start bluepill:")
|
|
161
163
|
$stderr.puts(format("%s `%s`", e.class.name, e.message))
|
|
162
164
|
$stderr.puts(e.backtrace)
|
|
@@ -245,15 +247,29 @@ module Bluepill
|
|
|
245
247
|
|
|
246
248
|
# Return the daemon's version, which the CLI checks against its own
|
|
247
249
|
#
|
|
248
|
-
#
|
|
250
|
+
# It's a String, since Marshal sends a module as only its name, which
|
|
251
|
+
# the CLI would load as its own Version.
|
|
252
|
+
#
|
|
253
|
+
# @return [String] the version, such as "0.2.9"
|
|
249
254
|
#
|
|
250
255
|
# @api private
|
|
251
256
|
def version
|
|
252
|
-
Version
|
|
257
|
+
Version.to_s
|
|
253
258
|
end
|
|
254
259
|
|
|
255
260
|
protected
|
|
256
261
|
|
|
262
|
+
# Log an error that stopped the daemon at crit, with its backtrace
|
|
263
|
+
#
|
|
264
|
+
# @param [StandardError] error the error
|
|
265
|
+
#
|
|
266
|
+
# @return [void]
|
|
267
|
+
#
|
|
268
|
+
# @api private
|
|
269
|
+
def log_crash(error)
|
|
270
|
+
[format("Bluepill stopped: %s `%s`", error.class, error.message), *error.backtrace].each { |line| logger.crit(line) }
|
|
271
|
+
end
|
|
272
|
+
|
|
257
273
|
# Send a command to a process, a group, or every process
|
|
258
274
|
#
|
|
259
275
|
# @param [Symbol] method the command
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "bluepill/util/log_error"
|
|
4
|
+
|
|
3
5
|
module Bluepill
|
|
4
6
|
# Runs a process's check every so often, and fires its events when the
|
|
5
7
|
# check fails often enough
|
|
@@ -87,9 +89,13 @@ module Bluepill
|
|
|
87
89
|
|
|
88
90
|
# Create the check, with the options the watch doesn't take for itself
|
|
89
91
|
#
|
|
92
|
+
# It first warns about the options that bluepill 0.3.0 rejects.
|
|
93
|
+
#
|
|
90
94
|
# The condition gets the logger while it's created, so its own
|
|
91
95
|
# initialize can log, and again after, in case that initialize doesn't
|
|
92
|
-
# call super.
|
|
96
|
+
# call super. It gets its options as keyword arguments, which an
|
|
97
|
+
# initialize that takes an options Hash gets as the Hash, so a custom
|
|
98
|
+
# check can take them either way, as bluepill 0.3.0's need keywords.
|
|
93
99
|
#
|
|
94
100
|
# @param [Hash{Symbol => Object}] options the options the watch was
|
|
95
101
|
# created with, which stay as they are
|
|
@@ -98,9 +104,13 @@ module Bluepill
|
|
|
98
104
|
#
|
|
99
105
|
# @api private
|
|
100
106
|
def create_condition(options)
|
|
107
|
+
Deprecation.check_watch(@name, options, @fires)
|
|
101
108
|
condition_options = options.reject { |key, _| WATCH_KEYS.include?(key) }
|
|
102
109
|
condition_options[:logger] = @logger
|
|
103
|
-
|
|
110
|
+
condition = ProcessConditions[@name] #: untyped
|
|
111
|
+
Deprecation.check_condition_class(condition)
|
|
112
|
+
@process_condition = condition.new(**condition_options)
|
|
113
|
+
Deprecation.check_logger(@process_condition, @logger)
|
|
104
114
|
self.logger = @logger
|
|
105
115
|
end
|
|
106
116
|
|
|
@@ -144,9 +154,6 @@ module Bluepill
|
|
|
144
154
|
# @return [Array<Symbol>] the events to fire, empty unless the check
|
|
145
155
|
# ran and failed often enough
|
|
146
156
|
#
|
|
147
|
-
# @raise [StandardError] whatever the check raised, other than a
|
|
148
|
-
# System::PsError, after logging it
|
|
149
|
-
#
|
|
150
157
|
# @api private
|
|
151
158
|
def run(pid, tick_number = Clock.now)
|
|
152
159
|
# The same test as due?, written out to save a call on every check.
|
|
@@ -162,49 +169,45 @@ module Bluepill
|
|
|
162
169
|
|
|
163
170
|
# Run the check, add its value to the history, and log the history
|
|
164
171
|
#
|
|
172
|
+
# A check that raises is skipped: it adds nothing to the history and
|
|
173
|
+
# fires nothing, and runs again at its next interval.
|
|
174
|
+
#
|
|
165
175
|
# @param [Integer, nil] pid the process's pid
|
|
166
176
|
#
|
|
167
177
|
# @return [Array<Symbol>] the events to fire, empty unless enough of
|
|
168
|
-
# the last values failed for the watch to fire
|
|
169
|
-
#
|
|
170
|
-
# @raise [StandardError] whatever the check raised, other than a
|
|
171
|
-
# System::PsError, after logging it
|
|
178
|
+
# the last values failed for the watch to fire
|
|
172
179
|
#
|
|
173
180
|
# @api private
|
|
174
181
|
def run_check(pid)
|
|
175
|
-
|
|
176
|
-
value = @process_condition.run(pid, @include_children)
|
|
177
|
-
rescue => e
|
|
178
|
-
return check_failed(e)
|
|
179
|
-
end
|
|
182
|
+
value = @process_condition.run(pid, @include_children)
|
|
180
183
|
@history << HistoryValue.new(@process_condition.format_value(value), @process_condition.check?(value))
|
|
181
184
|
logger.info(to_s)
|
|
182
185
|
# Fire when enough of the values in the window failed
|
|
183
186
|
return @fires if @history.count { |v| !v.critical } >= @required
|
|
184
187
|
|
|
185
188
|
EMPTY_ARRAY
|
|
189
|
+
rescue => e
|
|
190
|
+
check_failed(e)
|
|
186
191
|
end
|
|
187
192
|
|
|
188
|
-
# Log an error the check raised
|
|
193
|
+
# Log an error the check raised
|
|
189
194
|
#
|
|
190
|
-
#
|
|
195
|
+
# A failed ps is a warning, since it says nothing about the check. Any
|
|
196
|
+
# other error is logged with its backtrace. Either way, the check reads
|
|
197
|
+
# nothing this time.
|
|
191
198
|
#
|
|
192
199
|
# @param [StandardError] error what the check raised
|
|
193
200
|
#
|
|
194
|
-
# @return [Array<Symbol>] no events
|
|
195
|
-
#
|
|
196
|
-
# @raise [StandardError] the error, unless it's a System::PsError
|
|
201
|
+
# @return [Array<Symbol>] no events
|
|
197
202
|
#
|
|
198
203
|
# @api private
|
|
199
204
|
def check_failed(error)
|
|
200
205
|
if error.is_a?(System::PsError)
|
|
201
|
-
# No data this time, so leave the history alone and check again next interval
|
|
202
206
|
logger.warning("#{@name}: #{error}")
|
|
203
|
-
EMPTY_ARRAY
|
|
204
207
|
else
|
|
205
|
-
|
|
206
|
-
raise
|
|
208
|
+
Util.log_error(logger, "#{@name} check failed", error)
|
|
207
209
|
end
|
|
210
|
+
EMPTY_ARRAY
|
|
208
211
|
end
|
|
209
212
|
|
|
210
213
|
# Forget the values the check read, as when the process changes state
|
data/lib/bluepill/controller.rb
CHANGED
|
@@ -16,6 +16,15 @@ module Bluepill
|
|
|
16
16
|
class Controller
|
|
17
17
|
include Directory
|
|
18
18
|
|
|
19
|
+
# The shell command that tails a log file ($1) through grep -E ($2)
|
|
20
|
+
#
|
|
21
|
+
# The path and the pattern are the shell's arguments, so they're never
|
|
22
|
+
# parsed as shell code, whatever characters they hold.
|
|
23
|
+
TAIL_COMMAND = 'tail -n 100 -f "$1" | grep -E "$2"'
|
|
24
|
+
|
|
25
|
+
# What the CLI says when the daemon runs another version of bluepill
|
|
26
|
+
OUT_OF_DATE = "The running version of your daemon seems to be out of date."
|
|
27
|
+
|
|
19
28
|
attr_accessor :base_dir, :log_file
|
|
20
29
|
attr_reader :base_directory
|
|
21
30
|
|
|
@@ -144,7 +153,7 @@ module Bluepill
|
|
|
144
153
|
# Tail the daemon's log, showing only a process or group's lines
|
|
145
154
|
#
|
|
146
155
|
# It falls back to the controller's log_file when the daemon doesn't
|
|
147
|
-
# name one, and replaces the CLI with tail.
|
|
156
|
+
# name one, and replaces the CLI with tail piped through grep.
|
|
148
157
|
#
|
|
149
158
|
# @param [String] application the application's name
|
|
150
159
|
# @param [String, nil] requested_pattern the process or group
|
|
@@ -153,14 +162,11 @@ module Bluepill
|
|
|
153
162
|
#
|
|
154
163
|
# @api private
|
|
155
164
|
def tail_log(application, requested_pattern)
|
|
156
|
-
log_file_location = send_to_daemon(application, :log_file)
|
|
157
|
-
log_file_location = log_file if log_file_location.
|
|
165
|
+
log_file_location = send_to_daemon(application, :log_file).to_s
|
|
166
|
+
log_file_location = log_file.to_s if log_file_location.rstrip.empty?
|
|
158
167
|
|
|
159
|
-
pattern = grep_pattern(application, requested_pattern)
|
|
160
|
-
|
|
161
|
-
tail = "tail -n 100 -f #{log_file_location} | grep -E '#{pattern}'"
|
|
162
168
|
puts "Tailing log for #{requested_pattern}..."
|
|
163
|
-
Kernel.exec(
|
|
169
|
+
Kernel.exec("sh", "-c", TAIL_COMMAND, "sh", log_file_location, grep_pattern(application, requested_pattern))
|
|
164
170
|
end
|
|
165
171
|
|
|
166
172
|
# Send one of the PROCESS_COMMANDS to the daemon and print what it did
|
|
@@ -220,6 +226,11 @@ module Bluepill
|
|
|
220
226
|
|
|
221
227
|
# Abort unless an application's daemon runs this version of bluepill
|
|
222
228
|
#
|
|
229
|
+
# A daemon older than 0.2.9 answers with its Version module, which
|
|
230
|
+
# Marshal loads as the CLI's own, so it can't say which version it runs,
|
|
231
|
+
# and the CLI talks to it as before, with a warning, since bluepill
|
|
232
|
+
# 0.3.0's CLI refuses it.
|
|
233
|
+
#
|
|
223
234
|
# @param [String] application the application's name
|
|
224
235
|
#
|
|
225
236
|
# @return [void]
|
|
@@ -227,9 +238,11 @@ module Bluepill
|
|
|
227
238
|
# @api private
|
|
228
239
|
def verify_version!(application)
|
|
229
240
|
version = Socket.client_command(base_dir, application, "version")
|
|
230
|
-
|
|
241
|
+
return Deprecation.check_daemon_version(version) if version.equal?(Version) || Version.to_s.eql?(version)
|
|
242
|
+
|
|
243
|
+
abort("#{OUT_OF_DATE}\nDaemon Version: #{version}, CLI Version: #{Version}")
|
|
231
244
|
rescue ArgumentError
|
|
232
|
-
abort(
|
|
245
|
+
abort(OUT_OF_DATE)
|
|
233
246
|
end
|
|
234
247
|
end
|
|
235
248
|
end
|
|
@@ -0,0 +1,193 @@
|
|
|
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
|