bluepill 0.2.7 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +144 -1
  3. data/README.md +17 -10
  4. data/bin/bluepill +8 -2
  5. data/bluepill.gemspec +1 -1
  6. data/lib/bluepill/application/lifecycle.rb +43 -31
  7. data/lib/bluepill/application/listener.rb +1 -1
  8. data/lib/bluepill/application/previous_daemon.rb +14 -14
  9. data/lib/bluepill/application.rb +48 -28
  10. data/lib/bluepill/base_directory.rb +18 -20
  11. data/lib/bluepill/check_registry.rb +104 -0
  12. data/lib/bluepill/clock.rb +1 -3
  13. data/lib/bluepill/condition_watch.rb +61 -67
  14. data/lib/bluepill/controller/directory.rb +1 -3
  15. data/lib/bluepill/controller.rb +46 -38
  16. data/lib/bluepill/dsl/app_proxy.rb +69 -58
  17. data/lib/bluepill/dsl/attributes.rb +135 -0
  18. data/lib/bluepill/dsl/process_factory/child_factory.rb +80 -0
  19. data/lib/bluepill/dsl/process_factory/registry.rb +6 -26
  20. data/lib/bluepill/dsl/process_factory.rb +86 -70
  21. data/lib/bluepill/dsl/process_proxy.rb +61 -158
  22. data/lib/bluepill/dsl.rb +15 -6
  23. data/lib/bluepill/errors.rb +190 -0
  24. data/lib/bluepill/group.rb +14 -37
  25. data/lib/bluepill/logger.rb +55 -97
  26. data/lib/bluepill/process/attributes.rb +66 -32
  27. data/lib/bluepill/process/children.rb +4 -6
  28. data/lib/bluepill/process/pid.rb +41 -35
  29. data/lib/bluepill/process/state_machine.rb +15 -59
  30. data/lib/bluepill/process/stop_signals.rb +120 -0
  31. data/lib/bluepill/process/transition.rb +1 -3
  32. data/lib/bluepill/process/transition_callbacks.rb +2 -19
  33. data/lib/bluepill/process/triggers.rb +90 -0
  34. data/lib/bluepill/process/user_commands.rb +1 -1
  35. data/lib/bluepill/process/watches.rb +9 -23
  36. data/lib/bluepill/process.rb +70 -55
  37. data/lib/bluepill/process_commands/execution.rb +14 -22
  38. data/lib/bluepill/process_commands/hooks.rb +1 -31
  39. data/lib/bluepill/process_commands/stop_signals.rb +12 -17
  40. data/lib/bluepill/process_commands.rb +10 -8
  41. data/lib/bluepill/process_conditions/always_true.rb +2 -6
  42. data/lib/bluepill/process_conditions/below_threshold.rb +6 -8
  43. data/lib/bluepill/process_conditions/cpu_usage.rb +1 -4
  44. data/lib/bluepill/process_conditions/file_time.rb +8 -9
  45. data/lib/bluepill/process_conditions/http.rb +28 -43
  46. data/lib/bluepill/process_conditions/mem_usage.rb +7 -45
  47. data/lib/bluepill/process_conditions/process_condition.rb +30 -32
  48. data/lib/bluepill/process_conditions/zombie_process.rb +2 -6
  49. data/lib/bluepill/process_conditions.rb +5 -14
  50. data/lib/bluepill/process_journal/cleanup.rb +5 -53
  51. data/lib/bluepill/process_journal/config.rb +73 -0
  52. data/lib/bluepill/process_journal/entries.rb +128 -0
  53. data/lib/bluepill/process_journal/journal.rb +69 -0
  54. data/lib/bluepill/process_journal/kind.rb +60 -0
  55. data/lib/bluepill/process_journal/lock.rb +9 -4
  56. data/lib/bluepill/process_journal.rb +13 -324
  57. data/lib/bluepill/process_statistics.rb +3 -7
  58. data/lib/bluepill/socket.rb +19 -17
  59. data/lib/bluepill/system/command_options.rb +135 -0
  60. data/lib/bluepill/system/command_result.rb +73 -0
  61. data/lib/bluepill/system/command_setup.rb +3 -4
  62. data/lib/bluepill/system/commands.rb +21 -18
  63. data/lib/bluepill/system/daemon.rb +19 -14
  64. data/lib/bluepill/system/files.rb +35 -0
  65. data/lib/bluepill/system/ps.rb +20 -17
  66. data/lib/bluepill/system/ps_table.rb +7 -9
  67. data/lib/bluepill/system/usage.rb +155 -0
  68. data/lib/bluepill/system.rb +7 -192
  69. data/lib/bluepill/trigger.rb +22 -32
  70. data/lib/bluepill/triggers/flapping.rb +12 -8
  71. data/lib/bluepill/units.rb +7 -21
  72. data/lib/bluepill/util/log_error.rb +28 -0
  73. data/lib/bluepill/version.rb +12 -22
  74. data/lib/bluepill.rb +1 -0
  75. data/sig/bluepill/application.rbs +17 -12
  76. data/sig/bluepill/attributes.rbs +48 -0
  77. data/sig/bluepill/checks.rbs +43 -30
  78. data/sig/bluepill/dsl.rbs +98 -55
  79. data/sig/bluepill/errors.rbs +48 -0
  80. data/sig/bluepill/logger.rbs +15 -31
  81. data/sig/bluepill/process.rbs +42 -304
  82. data/sig/bluepill/process_commands.rbs +235 -0
  83. data/sig/bluepill/stop_signals.rbs +21 -0
  84. data/sig/bluepill/system.rbs +154 -99
  85. data/sig/bluepill/version.rbs +17 -0
  86. data/sig/bluepill.rbs +4 -17
  87. data/sig/manifest.yaml +1 -0
  88. metadata +22 -3
  89. data/lib/bluepill/dsl/process_factory/children.rb +0 -73
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d664e72f8442b19af1fb89f3fcde512ce4d59c883801117a9d7bc25f5353db8
4
- data.tar.gz: 77794cc2c1df9fa08ac568b33098333f1adc67802cb943e00c0ee033a7cdf647
3
+ metadata.gz: fa9f8a199b7c2f30858345bc94b934e3a15be6776595ea4481c61722340812b8
4
+ data.tar.gz: b33c36a84b7bbe956866889eca7838211f4d40942e75b3e6fefd33b6c81b6958
5
5
  SHA512:
6
- metadata.gz: 5a16b8fc0f63a6e1aa90eef446e9e7841c3f88442db3cb8e9f7b49518770694ad09992b859229151d63496fc11e2283731af559df8eb2a25e737312382bb8581
7
- data.tar.gz: 0e417a4c4072c3f9435e185ba1ee2ac7f013f01f10d18041e6ce2eea48f39776cd9ac477644586c85e5a6d7b621ef2fee2510783b13944e706d6886d6f2cd3da
6
+ metadata.gz: 42b736d7e86289628a9a0b057f01d9e0b379a42048b6903da13090429a4831255adcefd07db3cccc3ab19b816ad9281ad58d692779e171a3ea767cb24c0f96f6
7
+ data.tar.gz: e8dcc83be7c7a2df1f6f030f13dc11ef75bd98b087dce958cbce07f13812193693bdd7dfafd3ee2e8d9753b913b41341bb8b1db5d588882aa748f789d7ff9445
data/CHANGELOG.md CHANGED
@@ -7,6 +7,117 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.3.0] - 2026-11-02
11
+
12
+ ### Upgrading from 0.2
13
+
14
+ Most pill files work with 0.3.0 unchanged. Upgrade to 0.2.9 first, and run `bluepill load`: it warns, with a `DEPRECATION:` line, about each of these that it can find in your pill file and your custom checks and triggers, and a pill file that loads without any works with 0.3.0. Check these before you upgrade:
15
+
16
+ - **Bluepill needs Ruby 3.0 or newer, or JRuby 9.4 or newer.** On Ruby 2.7, stay on 0.2.9.
17
+ - **A custom check or trigger takes its options as keyword arguments.** One written as `def initialize(options = {})` that calls `super` now fails with an `ArgumentError`, since `super` passes the hash on as one positional argument. Name the options it needs and pass the rest on, as the README's example does: `def initialize(path:, below:, **options)`, then `super(**options)`. One written for bluepill 0.1, which defines `check`, also needs it renamed `check?`.
18
+ - **An application option that bluepill doesn't know fails the config.** `Bluepill.application("app", log_flie: "/var/log/app.log")` now stops with Ruby's unknown keyword error. Before, bluepill ignored the option.
19
+ - **A check without an option it needs fails the config.** `checks :mem_usage`, `:cpu_usage` or `:running_time` without `below:`, and `:file_time` without `filename:` or `below:`, now stop the pill file from loading, with Ruby's missing keyword error. Before, `mem_usage` without `below:` always passed, and the others raised an error each time they ran. `:http` without `url:` fails with the same error, where it failed with a `URI::InvalidURIError`.
20
+ - **A check or trigger option that bluepill doesn't know fails the config.** A misspelled option, such as `evry: 10`, or one meant for another check, such as `within:` on an `http` check, now stops the pill file from loading, with Ruby's unknown keyword error. Before, bluepill ignored it.
21
+ - **Pass options kept in a hash with `**`.** A pill file that keeps a check's or the application's options in a variable passes them as `process.checks :mem_usage, **options`, since a hash passed without `**` no longer counts as options.
22
+ - **An https `http` check verifies the server's certificate.** One against a self-signed or otherwise invalid certificate now fails the check. Add `verify_ssl: false` to keep checking it without verification.
23
+ - **Set attributes with `=`.** `process.daemonize!` and `process.start_command "cmd"` no longer work. Write `process.daemonize = true` and `process.start_command = "cmd"`.
24
+ - **`on_start_timeout`, `fires:` and a custom trigger's `dispatch!` take Symbols**, such as `process.on_start_timeout = :unmonitor` or `fires: :stop`, from `:start`, `:stop`, `:unmonitor` and `:restart`.
25
+ - **Two checks of the same kind both run.** A process with two `checks :http` of different URLs, of which 0.2 ran only the last, now runs both, so the first one can restart the process too.
26
+ - **A `monitor_children` block needs a `stop_command`, and runs once at load.** Bluepill runs it when the pill file loads, with `actual_pid` nil, to check it, and fails the config if it sets no `stop_command`. `monitor_children` needs a block, and a process block can't set `monitor_children` or `child_process_factory` itself.
27
+ - **A custom check that subclasses `MemUsage` gets bytes.** Its `run`, `check?` and `format_value` see the memory usage in bytes, where they saw kilobytes.
28
+ - **Call `super` first in a custom check's `initialize`.** A check gets its logger only through the `logger:` keyword, which `super` stores, so one that doesn't call `super` has no logger. Don't set a check's or trigger's `logger` yourself: the writer is gone.
29
+ - **Upgrade the daemon along with the CLI.** A 0.3.0 `bluepill` command says a 0.2 daemon is out of date, so run `bluepill load` again after upgrading. Bluepill monitors the running processes again without restarting them.
30
+
31
+ ### Added
32
+
33
+ - `Bluepill::Error`, the base of the errors that stop the `bluepill` command, with the status it exits with: `ConfigError`, for a mistake in a pill file, such as a misspelled process attribute or two processes with the same pid file, `StartupError`, `PreviousDaemonError`, `AlreadyRunningError`, `ConnectionError`, `VersionMismatchError`, `UnknownCommandError` and `DaemonError`.
34
+ - The `http` check's `verify_ssl:` option. Set it to false for a server with a self-signed certificate.
35
+ - A custom check or trigger can be defined in any module, since bluepill finds it by its class name.
36
+ - The daemon logs what stops it at `crit`, with the backtrace, since its stderr is `/dev/null`.
37
+
38
+ ### Changed
39
+
40
+ - **Breaking:** a misspelled process attribute raises `Bluepill::ConfigError` instead of `NoMethodError`. Like the other mistakes that a config check finds, such as a missing `start_command`, `bluepill load` prints its message and exits with status 6, where it showed a backtrace and exited with status 1.
41
+ - **Breaking:** the options of `Bluepill.application` and `checks` are keyword arguments, all the way to the application, the checks and the triggers, so a misspelled, unknown or missing option fails when the pill file loads. A custom check or trigger takes its options as keyword arguments too (see "Upgrading from 0.2").
42
+ - An exception in a check or trigger is logged, with its backtrace, and no longer stops the daemon. The check is skipped until its next interval, and doesn't count toward `times`.
43
+ - A config error's message starts with the pill file's line, as in `app.pill.rb:5: Unknown attribute ...`.
44
+ - **Breaking:** a misspelled application attribute, such as `app.uidd = "deploy"`, raises `Bluepill::ConfigError` with a suggestion, as a misspelled process attribute does.
45
+ - **Breaking:** an unknown check name raises `Bluepill::ConfigError` with a did-you-mean suggestion, where it raised `NameError`.
46
+ - **Breaking:** `fires:` takes only `:start`, `:stop`, `:unmonitor` or `:restart`, and anything else fails the pill file with a `Bluepill::ConfigError`. Before, bluepill called any public method of the process with that name.
47
+ - **Breaking:** `on_start_timeout` defaults to `:start`, and a value that isn't one of `:start`, `:stop`, `:unmonitor` or `:restart` fails the config.
48
+ - **Breaking:** a custom check that doesn't define `run` and `check?`, or a trigger that doesn't define `notify`, fails the pill file when it loads, where it raised each time it ran.
49
+ - **Breaking:** the `http` check verifies TLS certificates.
50
+ - **Breaking:** reading an attribute that isn't set returns nil instead of raising `NameError`.
51
+ - **Breaking:** the library raises a `Bluepill::Error` instead of calling `exit` or `abort`. `bin/bluepill` and `Bluepill.application` print its message and exit with the same statuses as before.
52
+ - **Breaking:** `Bluepill::Logger`'s log methods take only the message, and `prefix_with` is the only way to make a prefixed logger (the `prefix:` option is gone).
53
+ - A mistake in a `monitor_children` block, such as a missing `stop_command`, fails the config when it loads. Before, the daemon exited the first time it found a child. `monitor_children` without a block fails the config.
54
+ - The daemon traps signals and creates its pids directory when it starts, not while the pill file loads.
55
+ - **Breaking:** the commands a process runs take a `System::CommandOptions`, and `System.execute_blocking` returns a `System::CommandResult`, instead of Hashes. `System.daemonize` takes the pid file and the logger as keywords.
56
+ - **Breaking:** each process reaches its pid and process group journals through `ProcessJournal.for(name)`, and a journal lock held too long raises `ProcessJournal::LockTimeoutError`.
57
+ - **Breaking:** the ps table is kept in `System`'s own state, and `System.store` is gone.
58
+ - Checking a process's CPU takes 8% fewer instructions, and the `mem_usage` check 1.4% fewer.
59
+ - A process gets its logger, prefixed with the names of its app, its group and itself, when it's made, and passes it to its watches, checks and triggers as they're made, instead of being handed a new logger when it joins its group.
60
+ - A process's `stop_signals` is parsed and checked once, when the pill file loads, into a `Bluepill::Process::StopSignals`.
61
+ - **Breaking:** `Process#stop_signals` returns a `Bluepill::Process::StopSignals` instead of an Array (`to_a` gives the Array), and `Process#stop_signals=` raises `Bluepill::ConfigError` for a malformed Array, a monitored child's too.
62
+
63
+ ### Removed
64
+
65
+ - **Breaking:** a custom check that defines `check`, as in bluepill 0.1, no longer works. Name the method `check?`, as bluepill 0.2 does.
66
+ - **Breaking:** support for Ruby 2.7. Bluepill 0.3.0 needs Ruby 3.0 or newer, or JRuby 9.4 or newer. Bluepill 0.2.9 still runs on Ruby 2.7.
67
+ - **Breaking:** the undocumented `name!` and `name value` forms of setting a process attribute.
68
+ - **Breaking:** setting `monitor_children` or `child_process_factory` in a process block. Use `monitor_children` with a block.
69
+ - **Breaking:** the `logger=` writers of `Process`, `Process::Watches`, `Process::Triggers`, `ConditionWatch`, `ProcessConditions::ProcessCondition` and `Trigger`. A custom check or trigger gets its logger only through the `logger:` keyword.
70
+ - **Breaking:** `Process#start`, `#stop`, `#restart` and `#unmonitor` (use `dispatch!`), `Trigger.[]` and `ProcessConditions.[]` (use `CheckRegistry.fetch`), `Group#process_logger`, and `ConditionWatch::HistoryValue#critical` (now `passed`).
71
+
72
+ ### Fixed
73
+
74
+ - Two checks of the same kind, such as two `:http` checks of different URLs, both run. Before, only the last one did.
75
+ - 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.
76
+ - `bluepill log` quotes the log file's path and the pattern, so a path with spaces or shell characters works.
77
+
78
+ ## [0.2.9] - 2026-11-02
79
+
80
+ ### Added
81
+
82
+ - 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.
83
+ - 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.
84
+
85
+ ### Deprecated
86
+
87
+ 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.
88
+
89
+ - Running on Ruby 2.7. Bluepill 0.3.0 needs Ruby 3.0 or newer, or JRuby 9.4 or newer.
90
+ - 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.
91
+ - 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.
92
+ - 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.
93
+ - 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.
94
+ - 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)`.
95
+ - 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.
96
+ - A custom check or trigger whose `initialize` doesn't call `super`. Bluepill 0.3.0 gives it its logger only through `super`.
97
+ - Calling `logger=` on a check or trigger from outside bluepill. Bluepill 0.3.0 removes it.
98
+ - A custom trigger that dispatches an event as a String, such as `dispatch!("start")`. Bluepill 0.3.0 takes only Symbols.
99
+ - 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.
100
+ - 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.
101
+ - 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"`.
102
+ - 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.
103
+ - 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.
104
+ - 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.
105
+ - 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.
106
+ - 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.
107
+ - 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.
108
+
109
+ ### Fixed
110
+
111
+ - 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.
112
+ - 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.
113
+ - The daemon logs what stops it at `crit`, with its backtrace, since its stderr is `/dev/null`.
114
+ - `bluepill load` no longer prints an error when the daemon it replaces exits just before it's signaled.
115
+
116
+ ### Security
117
+
118
+ - 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.
119
+ - `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.
120
+
10
121
  ## [0.2.7] - 2026-11-02
11
122
 
12
123
  ### Changed
@@ -95,6 +206,35 @@ To upgrade, install 0.2.0 and run `bluepill load` with the same pill file. It re
95
206
 
96
207
  - The README's group example gave every process the same pid file, and its `stop_signals` example waited longer than its stop grace time, so bluepill refused to load either config.
97
208
 
209
+ ## [0.1.7] - 2026-11-02
210
+
211
+ ### Added
212
+
213
+ - Warnings about what bluepill 0.2.0 and later will change, each in a line that starts with `DEPRECATION:`, once each, on stderr, where `bluepill load` shows it, and in bluepill's log. Each says what to do now. See Deprecated for what they warn about.
214
+
215
+ ### Deprecated
216
+
217
+ - An `http` check of an https URL that doesn't set `verify_ssl:`, since bluepill 0.3.0 verifies its certificate by default. Set `verify_ssl: true` to verify it now, or `verify_ssl: false` to keep checking a server with a self-signed certificate. Bluepill 0.2 ignores the option, so a pill file that sets it works with each version.
218
+ - Ruby 1.9.3 and JRuby 1.7. Bluepill 0.2.0 needs Ruby 2.0 or JRuby 9.0, and later 0.2 releases need Ruby 2.7 or JRuby 9.4. On those Rubies, stay on 0.1 until you upgrade Ruby.
219
+ - Setting a process attribute that bluepill doesn't know, such as a misspelled `start_comand`, which bluepill 0.1 ignores. Bluepill 0.2.0 fails the config on it. The warning names the attribute: remove it, or fix its name. `hook_timeout` and the hooks that 0.2.0 adds don't warn, though 0.1 ignores them.
220
+ - `pre_start_command`, which bluepill 0.2.0 runs like its other hooks: it kills one that runs longer than `hook_timeout`, 30 seconds by default, and starts the process even when the command can't run, such as a missing program. Bluepill 0.1 waits for it however long it takes. Set `hook_timeout`, which 0.1 ignores, for one that can take longer, such as a migration.
221
+ - A process with a `uid`, when bluepill runs as root. Bluepill 0.2.0 runs it with every group the user is in, as after logging in, and in the user's primary group when it sets no `gid`. Bluepill 0.1 gives it only its `gid` and `supplementary_groups`, and keeps it in root's groups when it sets no `gid`. Set `gid` and `supplementary_groups` to the groups it needs.
222
+ - `monitor_children` on a process with a `uid`, `gid` or `supplementary_groups`, when bluepill runs as root. Bluepill 0.2.0 runs the children's commands, such as their `stop_command`, as the parent's user and groups, where 0.1 runs them as root. Make sure they work as that user, or run one that needs root with `sudo`.
223
+ - A custom trigger that reads anything of the transition its `notify` gets but `from_name`, `to_name` and `loopback?`, such as `from`, `to` or `event`. Bluepill 0.2.0's transitions have only those three. The warning names the trigger and what it read. Bluepill's own `flapping` trigger only reads those three, so it gets its transitions as before.
224
+ - Bluepill 0.2.0 also changes some things that 0.1.7 can't warn about: it no longer loads ActiveSupport, so a pill file, check or trigger that uses `5.minutes.ago`, `blank?` or a unit such as `1.week` needs it required, a process's `state` is a Symbol, such as `:up`, the `state_machine` methods of a process, such as `state_name` and `can_start?`, are gone, and a custom check also gets a `logger:` option. Read 0.2.0's "Upgrading from 0.1" before upgrading.
225
+
226
+ ### Fixed
227
+
228
+ - The README's group example gave every process the same pid file, and its `stop_signals` example waited longer than its stop grace time, so bluepill refused to load either config.
229
+ - Bluepill timed its ticks, checks, grace times and flapping detection with the system clock, so a change to the clock, such as an NTP correction after a VM resumes, could put off ticks and checks for as long as the clock went back, or end grace times early when it went forward. It now times them with the monotonic clock, which only counts up, where Ruby has one (Ruby 2.1 and newer, and JRuby 9.0 and newer). On Ruby 1.9.3 and 2.0, and on JRuby 1.7, it still reads the system clock.
230
+ - An exception in a check, other than a failed `ps`, or in a trigger stopped the daemon, which exited with status 5 and left the processes unmonitored. Bluepill now logs it at `err`, with a line for each line of its backtrace, and keeps monitoring. The check adds nothing to its history and fires nothing, so it doesn't count toward `times`, and it runs again at its next interval. A tick that raises for any other reason is logged the same way, and the process ticks again next second.
231
+ - The CLI's check that the daemon runs the same version of bluepill never failed, since the daemon answered with its `Version` module, which Marshal loads as the CLI's own. The daemon now answers with its version as a String, and the CLI stops when it differs. A daemon from before 0.1.7 can't say which version it runs, so the CLI warns about it and goes on, as before. Run `bluepill load` again after upgrading to replace it.
232
+
233
+ ### Security
234
+
235
+ - `bluepill log` built a shell command with the log file's path and the pattern unquoted, so a path with a space broke the command, and a quote or `$(...)` in the path or the process name ran as shell code. It now passes them to `tail` and `grep` as the shell's arguments, so they are never parsed.
236
+ - The `http` check's `verify_ssl:` option. With `verify_ssl: true`, a check of an https URL verifies the server's certificate, so it fails against a server that isn't the one it names. It still doesn't verify it by default, as before, since that would fail the checks of servers with self-signed certificates. Bluepill 0.3.0 verifies it by default.
237
+
98
238
  ## [0.1.6] - 2026-11-02
99
239
 
100
240
  ### Security
@@ -852,12 +992,15 @@ Initial release.
852
992
  - Added the `bluepill` CLI with the `load`, `status`, `start`, `stop`, `restart`, `unmonitor`, `quit` and `log` commands.
853
993
  - Added syslog logging.
854
994
 
855
- [unreleased]: https://github.com/bluepill-rb/bluepill/compare/v0.2.7...HEAD
995
+ [unreleased]: https://github.com/bluepill-rb/bluepill/compare/v0.3.0...HEAD
996
+ [0.3.0]: https://github.com/bluepill-rb/bluepill/compare/v0.2.9...v0.3.0
997
+ [0.2.9]: https://github.com/bluepill-rb/bluepill/compare/v0.2.7...v0.2.9
856
998
  [0.2.7]: https://github.com/bluepill-rb/bluepill/compare/v0.2.5...v0.2.7
857
999
  [0.2.5]: https://github.com/bluepill-rb/bluepill/compare/v0.2.3...v0.2.5
858
1000
  [0.2.3]: https://github.com/bluepill-rb/bluepill/compare/v0.2.1...v0.2.3
859
1001
  [0.2.1]: https://github.com/bluepill-rb/bluepill/compare/v0.2.0...v0.2.1
860
1002
  [0.2.0]: https://github.com/bluepill-rb/bluepill/compare/v0.1.6...v0.2.0
1003
+ [0.1.7]: https://github.com/bluepill-rb/bluepill/compare/v0.1.6...v0.1.7
861
1004
  [0.1.6]: https://github.com/bluepill-rb/bluepill/compare/v0.1.5...v0.1.6
862
1005
  [0.1.5]: https://github.com/bluepill-rb/bluepill/compare/v0.1.4...v0.1.5
863
1006
  [0.1.4]: https://github.com/bluepill-rb/bluepill/compare/v0.1.3...v0.1.4
data/README.md CHANGED
@@ -60,10 +60,10 @@ end
60
60
 
61
61
  If you don't specify a stop command, a TERM signal will be sent by default. Similarly, the default restart action is to issue stop and then start.
62
62
 
63
- Bluepill only accepts the process attributes it knows, which are the ones this README describes. A misspelled or unsupported attribute fails when the config loads, and the error names the attribute, the process, and the closest attribute bluepill knows:
63
+ Bluepill only accepts the attributes it knows, which are the ones this README describes. A misspelled or unsupported attribute fails when the config loads, and the error names the attribute, the process, and the closest attribute bluepill knows. Bluepill prints the line of the pill file with the mistake before the error:
64
64
 
65
65
  ```
66
- Unknown attribute 'start_comand' for process 'process_name'. Did you mean 'start_command'?
66
+ app.pill.rb:5: Unknown attribute 'start_comand' for process 'process_name'. Did you mean 'start_command'?
67
67
  ```
68
68
 
69
69
  Now if we want to do something more meaningful, like actually monitor the process, we do:
@@ -78,7 +78,7 @@ Bluepill.application("app_name") do |app|
78
78
  end
79
79
  ```
80
80
 
81
- We added a line that checks every 10 seconds to make sure the cpu usage of this process is below 5 percent; 3 failed checks results in a restart. We can specify a two-element array for the _times_ option to say that it 3 out of 5 failed attempts results in a restart.
81
+ We added a line that checks every 10 seconds to make sure the cpu usage of this process is below 5 percent. Three failed checks in a row restart the process. We can specify a two-element array for the _times_ option to say that 3 out of 5 failed attempts result in a restart. A check restarts the process by default, and `fires:` picks other events instead, from `:start`, `:stop`, `:unmonitor` and `:restart`, such as `fires: :stop` or `fires: [:stop, :start]`.
82
82
 
83
83
  To watch memory usage, we just add one more line:
84
84
 
@@ -93,6 +93,8 @@ Bluepill.application("app_name") do |app|
93
93
  end
94
94
  ```
95
95
 
96
+ A process can have more than one check of a kind, such as two `:http` checks of different URLs.
97
+
96
98
  To watch the modification time of a file, e.g. a log file to ensure the process is actually working add one more line:
97
99
 
98
100
  ```ruby
@@ -213,6 +215,8 @@ To check for flapping:
213
215
  process.checks :flapping, times: 2, within: 30.seconds, retry_in: 7.seconds
214
216
  ```
215
217
 
218
+ To check that a URL answers, use `process.checks :http, url: "http://localhost:4567/", kind: :success, pattern: /html/, timeout: 3.seconds`. For an `https` URL, bluepill verifies the server's certificate. For a server with a self-signed certificate, add `verify_ssl: false`.
219
+
216
220
  To set the working directory to `cd` into when starting the command:
217
221
 
218
222
  ```ruby
@@ -327,6 +331,8 @@ process.monitor_children do |child_process|
327
331
  end
328
332
  ```
329
333
 
334
+ Bluepill runs this block once when the pill file loads, to check it, and again for each child it finds. `child_process.actual_pid` is the child's pid, and nil during that first run. The block must set a `stop_command`.
335
+
330
336
  Note `{{PID}}` will be substituted for the pid of process in both the stop and restart commands.
331
337
 
332
338
  ### Durations and sizes
@@ -337,16 +343,16 @@ If a pill file loads ActiveSupport, for example by loading a Rails app, ActiveSu
337
343
 
338
344
  ### Custom checks
339
345
 
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:
346
+ A check is a subclass of `Bluepill::ProcessConditions::ProcessCondition`, in any module, named after the check in camel case, so `checks :log_size` uses a class named `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. Name the ones it needs, and pass the rest to `super`, which rejects any that no check takes. `run` reads a value, and `check?` returns whether the value is fine:
341
347
 
342
348
  ```ruby
343
349
  module Bluepill
344
350
  module ProcessConditions
345
351
  class LogSize < ProcessCondition
346
- def initialize(options = {})
347
- super
348
- @path = options.fetch(:path)
349
- @below = options.fetch(:below)
352
+ def initialize(path:, below:, **options)
353
+ super(**options)
354
+ @path = path
355
+ @below = below
350
356
  end
351
357
 
352
358
  def run(_pid, _include_children)
@@ -370,7 +376,9 @@ Bluepill.application("app_name") do |app|
370
376
  end
371
377
  ```
372
378
 
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`. A check written for bluepill 0.1, which defines `check` instead of `check?`, still works.
379
+ `logger` writes to bluepill's log, with the app's and the process's names, like the built-in checks. The check gets it through the `logger:` keyword, which `super` stores, so call `super` first in `initialize`: a check that doesn't call `super` has no logger.
380
+
381
+ If `run`, `check?` or `format_value` raises, bluepill logs the error with its backtrace and skips the check until its next interval. It doesn't count toward `times`, and bluepill keeps monitoring. A check class must define both `run` and `check?`, or the pill file fails to load.
374
382
 
375
383
  ### Commands Don't Run in a Shell
376
384
 
@@ -504,7 +512,6 @@ JRuby allows you to run bluepill only in the foreground.
504
512
  This library aims to support and is [tested against][ci] the following Ruby
505
513
  implementations:
506
514
 
507
- * Ruby 2.7
508
515
  * Ruby 3.0 through 3.4
509
516
  * Ruby 4.0
510
517
  * JRuby 9.4 (only in the foreground)
data/bin/bluepill CHANGED
@@ -69,7 +69,7 @@ end
69
69
 
70
70
  APPLICATION_COMMANDS = %w[status start stop restart unmonitor quit log].freeze
71
71
 
72
- controller = Bluepill::Controller.new(options.slice(:base_dir, :log_file))
72
+ controller = Bluepill::Controller.new(**options.slice(:base_dir, :log_file))
73
73
 
74
74
  if controller.running_applications.include?(File.basename($PROGRAM_NAME)) && File.symlink?($PROGRAM_NAME)
75
75
  # bluepill was called as a symlink with the name of the target application
@@ -115,5 +115,11 @@ if options[:command] == "load"
115
115
  end
116
116
  else
117
117
  target = ARGV.shift
118
- controller.handle_command(options[:application], options[:command], target)
118
+ begin
119
+ controller.handle_command(options[:application], options[:command], target)
120
+ rescue Bluepill::Error => e
121
+ # The library raises what stops a command, with the status to exit with
122
+ $stderr.puts(e.message)
123
+ exit(e.exit_status)
124
+ end
119
125
  end
data/bluepill.gemspec CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  "rubygems_mfa_required" => "true"
23
23
  }
24
24
 
25
- spec.required_ruby_version = ">= 2.7"
25
+ spec.required_ruby_version = ">= 3.0"
26
26
 
27
27
  # sig has the RBS signatures, and the standard libraries they use in manifest.yaml
28
28
  spec.executables = %w[bluepill bpsv]
@@ -12,20 +12,28 @@ module Bluepill
12
12
 
13
13
  # Start the daemon
14
14
  #
15
- # It stops a previous daemon for the application, clears journal locks
16
- # it left behind, daemonizes unless it runs in the foreground, opens the
17
- # socket, and runs until a signal stops it. Processes that are already
18
- # running, from their pid files, are monitored again, not restarted, so
19
- # bluepill can be upgraded without restarting them.
15
+ # It creates the pids directory, stops a previous daemon for the
16
+ # application, clears journal locks it left behind, daemonizes unless
17
+ # it runs in the foreground, traps signals, opens the socket, and runs
18
+ # until a signal stops it. Processes that are already running, from
19
+ # their pid files, are monitored again, not restarted, so bluepill can
20
+ # be upgraded without restarting them.
20
21
  #
21
22
  # @return [void]
22
23
  #
24
+ # @raise [StartupError] if it can't create the pids directory
25
+ # @raise [PreviousDaemonError] if it can't stop a previous daemon
26
+ # @raise [AlreadyRunningError] if a daemon answers on the socket
27
+ #
23
28
  # @api private
24
29
  def start_server
30
+ setup_pids_dir
25
31
  kill_previous_bluepill
26
32
  ProcessJournal.clear_all_atomic_fs_locks
27
33
  become_process_group_leader
28
- daemonize_and_trap_signals unless foreground?
34
+ # Trapped after daemonizing, which ignores HUP
35
+ Daemonize.daemonize unless foreground?
36
+ setup_signal_traps
29
37
  logger.reopen
30
38
 
31
39
  $0 = "bluepilld: #{name}"
@@ -45,17 +53,6 @@ module Bluepill
45
53
  # A session leader can't, and it already leads its process group
46
54
  end
47
55
 
48
- # Daemonize, and trap the signals again
49
- #
50
- # @return [void]
51
- #
52
- # @api private
53
- def daemonize_and_trap_signals
54
- Daemonize.daemonize
55
- # Daemonizing ignores HUP, so trap it again to reopen the log on HUP
56
- setup_signal_traps
57
- end
58
-
59
56
  # Write the pid file, open the socket, and run the daemon
60
57
  #
61
58
  # @return [void]
@@ -123,36 +120,53 @@ module Bluepill
123
120
  end
124
121
  end
125
122
 
126
- # Create the logger and the pids directory
123
+ # Create the logger, prefixed with the application's name
127
124
  #
128
- # Bluepill opens its log file and creates its pids dir as the user that
129
- # runs it. The uid and gid in the config only apply to its processes.
130
- # It exits with status 5 if it can't.
125
+ # Bluepill opens its log file as the user that runs it.
131
126
  #
132
127
  # @return [void]
133
128
  #
129
+ # @raise [StartupError] if it can't open the log file
130
+ #
134
131
  # @api private
135
- def setup_logger_and_pids_dir
132
+ def setup_logger
136
133
  self.logger = ProcessJournal.logger = Logger.new(log_file: log_file, log_level: @log_level, stdout: foreground?).prefix_with(name)
137
- setup_pids_dir
138
134
  rescue SystemCallError => e
139
- $stderr.puts("Failed to start bluepill: #{e}")
140
- message = "The user running bluepill must be able to write to its log_file and base_dir. " \
141
- "The uid and gid in the config only apply to the processes it monitors."
142
- $stderr.puts(message)
143
- exit(5)
135
+ raise unwritable(e)
144
136
  end
145
137
 
146
138
  # Create the pids directory, and let every user write to it
147
139
  #
140
+ # Bluepill creates it as the user that runs it.
141
+ #
148
142
  # @return [void]
149
143
  #
144
+ # @raise [StartupError] if it can't
145
+ #
150
146
  # @api private
151
147
  def setup_pids_dir
152
148
  FileUtils.mkdir_p(pids_dir)
153
149
  # we need everybody to be able to write to the pids_dir as processes managed by
154
150
  # bluepill will be writing to this dir after they've dropped privileges
155
151
  FileUtils.chmod(0o777, pids_dir)
152
+ rescue SystemCallError => e
153
+ raise unwritable(e)
154
+ end
155
+
156
+ # Return the error for a file that bluepill can't write to
157
+ #
158
+ # @param [SystemCallError] error what writing to it raised
159
+ #
160
+ # @return [StartupError] the error, which says the uid and gid in the
161
+ # config only apply to the processes bluepill monitors
162
+ #
163
+ # @api private
164
+ def unwritable(error)
165
+ StartupError.new(
166
+ "Failed to start bluepill: #{error}\n" \
167
+ "The user running bluepill must be able to write to its log_file and base_dir. " \
168
+ "The uid and gid in the config only apply to the processes it monitors."
169
+ )
156
170
  end
157
171
 
158
172
  # Write the daemon's pid to its pid file
@@ -160,9 +174,7 @@ module Bluepill
160
174
  # @return [void]
161
175
  #
162
176
  # @api private
163
- def write_pid_file
164
- File.write(pid_file, ::Process.pid.to_s)
165
- end
177
+ def write_pid_file = File.write(pid_file, ::Process.pid.to_s)
166
178
  end
167
179
  end
168
180
  end
@@ -93,7 +93,7 @@ module Bluepill
93
93
  def daemon_command(command)
94
94
  # The backtrace is caller's lines, with no locations, so Ruby 3.1's
95
95
  # error_highlight doesn't add a snippet of this file to the message
96
- DAEMON_COMMANDS.detect { |name| name.to_s.eql?(command) } ||
96
+ DAEMON_COMMANDS.detect { |known| known.name.eql?(command) } ||
97
97
  raise(NoMethodError, "Unknown command `#{command}`", caller)
98
98
  end
99
99
 
@@ -13,11 +13,13 @@ module Bluepill
13
13
 
14
14
  # Interrupt a daemon for this application that's still running
15
15
  #
16
- # It waits up to kill_timeout half seconds for the daemon to exit, and
17
- # exits with status 4 if it doesn't, or if signaling it fails.
16
+ # It waits up to kill_timeout half seconds for the daemon to exit.
18
17
  #
19
18
  # @return [void]
20
19
  #
20
+ # @raise [PreviousDaemonError] if signaling it fails, or it doesn't
21
+ # exit in time
22
+ #
21
23
  # @api private
22
24
  def kill_previous_bluepill
23
25
  previous_pid = interrupt_previous_bluepill
@@ -26,10 +28,10 @@ module Bluepill
26
28
 
27
29
  # Interrupt the previous daemon, if its pid file names a live one
28
30
  #
29
- # It exits with status 4 if signaling it fails, unless it's gone.
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
+ #
34
+ # @raise [PreviousDaemonError] if signaling it fails
33
35
  #
34
36
  # @api private
35
37
  def interrupt_previous_bluepill
@@ -40,10 +42,11 @@ module Bluepill
40
42
  puts "Killing previous bluepilld[#{previous_pid}]"
41
43
  ::Process.kill(2, previous_pid)
42
44
  previous_pid
45
+ rescue Errno::ESRCH
46
+ # It exited after previous_bluepill_pid saw it alive
47
+ nil
43
48
  rescue => e
44
- $stderr.puts "Encountered error trying to kill previous bluepill:"
45
- $stderr.puts "#{e.class}: #{e}"
46
- exit(4) unless e.instance_of?(Errno::ESRCH)
49
+ raise PreviousDaemonError, "Encountered error trying to kill previous bluepill:\n#{e.class}: #{e}"
47
50
  end
48
51
 
49
52
  # Return the pid of a previous daemon that's still running
@@ -59,12 +62,12 @@ module Bluepill
59
62
 
60
63
  # Wait up to kill_timeout half seconds for the previous daemon to exit
61
64
  #
62
- # It exits with status 4 if the daemon is still running after.
63
- #
64
65
  # @param [Integer] previous_pid the previous daemon's pid
65
66
  #
66
67
  # @return [void]
67
68
  #
69
+ # @raise [PreviousDaemonError] if it's still running after
70
+ #
68
71
  # @api private
69
72
  def wait_for_previous_bluepill(previous_pid)
70
73
  kill_timeout.times do |_i|
@@ -73,10 +76,7 @@ module Bluepill
73
76
  break unless System.pid_alive?(previous_pid)
74
77
  end
75
78
 
76
- return unless System.pid_alive?(previous_pid)
77
-
78
- $stderr.puts "Previous bluepilld[#{previous_pid}] didn't die"
79
- exit(4)
79
+ raise PreviousDaemonError, "Previous bluepilld[#{previous_pid}] didn't die" if System.pid_alive?(previous_pid)
80
80
  end
81
81
  end
82
82
  end