bluepill 0.1.5 → 0.1.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea20c4756cdf70d6b42f9c86361254c13bf933038bd3a5baa9e6218cfea17296
4
- data.tar.gz: 1a7999e78a5e25ede02d2ea71d1f165a9b5d44afc658a9815477e2cb35f5b048
3
+ metadata.gz: 6cab6ca69f155a98057f6f2d051db400e63a5c50c129605b7fbdc721cd30dd46
4
+ data.tar.gz: 14ce6d8846249041f94bc49758733d9689c65e7d95cc3c9edff972a8fdb69529
5
5
  SHA512:
6
- metadata.gz: 81675c58e49c91da17dbc60e052158ef1072fa6f711c3da32fe73040ad6732d7949c00e44a0055c3dacb904fdef18fb792ab04a7a8fb8c9896a1f15cc6d11875
7
- data.tar.gz: d55cdef40d00d3a4bb085b8ee67a93a6fe00bbe8d6b32a512a196952b5ded55a3e80e1fa95c143a632203bcf71cdf4c055e6ba88363ddf2ba434d10d37cf3226
6
+ metadata.gz: '025582cb8e694b52da97e72a718b370510ea1a9290b8971d29839dec7da79e2148e931066be177332f54f381b256ecc55f4ce92c2ad6d02d1dc497b2ec8608d7'
7
+ data.tar.gz: 55fed4e18256e80a74a41b7716e96f13f1fbbc46e29e112c97de54b2f6690d92f69116b8da8c766064e1856d14b54f22531416bb577366992e63a68b20b4ddc5
data/CHANGELOG.md CHANGED
@@ -7,6 +7,41 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.1.7] - 2026-11-02
11
+
12
+ ### Added
13
+
14
+ - 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.
15
+
16
+ ### Deprecated
17
+
18
+ - 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.
19
+ - 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.
20
+ - 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.
21
+ - `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.
22
+ - 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.
23
+ - `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`.
24
+ - 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.
25
+ - 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.
26
+
27
+ ### Fixed
28
+
29
+ - 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.
30
+ - 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.
31
+ - 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.
32
+ - 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.
33
+
34
+ ### Security
35
+
36
+ - `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.
37
+ - 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.
38
+
39
+ ## [0.1.6] - 2026-11-02
40
+
41
+ ### Security
42
+
43
+ - 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.
44
+
10
45
  ## [0.1.5] - 2026-11-01
11
46
 
12
47
  ### Removed
@@ -758,7 +793,9 @@ Initial release.
758
793
  - Added the `bluepill` CLI with the `load`, `status`, `start`, `stop`, `restart`, `unmonitor`, `quit` and `log` commands.
759
794
  - Added syslog logging.
760
795
 
761
- [unreleased]: https://github.com/bluepill-rb/bluepill/compare/v0.1.5...HEAD
796
+ [unreleased]: https://github.com/bluepill-rb/bluepill/compare/v0.1.7...HEAD
797
+ [0.1.7]: https://github.com/bluepill-rb/bluepill/compare/v0.1.6...v0.1.7
798
+ [0.1.6]: https://github.com/bluepill-rb/bluepill/compare/v0.1.5...v0.1.6
762
799
  [0.1.5]: https://github.com/bluepill-rb/bluepill/compare/v0.1.4...v0.1.5
763
800
  [0.1.4]: https://github.com/bluepill-rb/bluepill/compare/v0.1.3...v0.1.4
764
801
  [0.1.3]: https://github.com/bluepill-rb/bluepill/compare/v0.1.2...v0.1.3
data/README.md CHANGED
@@ -111,6 +111,20 @@ Bluepill.application("app_name") do |app|
111
111
  end
112
112
  ```
113
113
 
114
+ To restart a process when a URL stops answering:
115
+
116
+ ```ruby
117
+ Bluepill.application("app_name") do |app|
118
+ app.process("process_name") do |process|
119
+ process.start_command = "/usr/bin/some_start_command"
120
+ process.pid_file = "/tmp/some_pid_file.pid"
121
+ process.checks :http, every: 30.seconds, url: "https://localhost:4443/status", kind: :success, timeout: 5.seconds, verify_ssl: true
122
+ end
123
+ end
124
+ ```
125
+
126
+ Bluepill 0.1 doesn't verify an https URL's certificate unless the check sets `verify_ssl: true`. Bluepill 0.3.0 verifies it by default, so set `verify_ssl: true` now, or `verify_ssl: false` for a server with a self-signed certificate.
127
+
114
128
  We can tell bluepill to give a process some grace time to start/stop/restart before resuming monitoring:
115
129
 
116
130
  ```ruby
@@ -135,7 +149,7 @@ Bluepill.application("app_name") do |app|
135
149
  app.process("process_name_#{i}") do |process|
136
150
  process.group = "mongrels"
137
151
  process.start_command = "/usr/bin/some_start_command"
138
- process.pid_file = "/tmp/some_pid_file.pid"
152
+ process.pid_file = "/tmp/some_pid_file_#{i}.pid"
139
153
  end
140
154
  end
141
155
  end
@@ -263,13 +277,16 @@ Bluepill.application("app_name") do |app|
263
277
  process.start_command = "/usr/bin/some_start_command"
264
278
  process.pid_file = "/tmp/some_pid_file.pid"
265
279
  process.stop_signals = [:quit, 30.seconds, :term, 5.seconds, :kill]
280
+ process.stop_grace_time = 45.seconds
266
281
  end
267
282
  end
268
283
  ```
269
284
 
270
285
  We added a line that will send a SIGQUIT, wait 30 seconds and check to
271
286
  see if the process is still up, send a SIGTERM, wait 5 seconds and check
272
- to see if the process is still up, and finally send a SIGKILL.
287
+ to see if the process is still up, and finally send a SIGKILL. The
288
+ `stop_grace_time` has to be longer than the delays added up, here 35
289
+ seconds, so the last signal has time to work.
273
290
 
274
291
  And lastly, to monitor child processes:
275
292
 
@@ -13,6 +13,12 @@ module Bluepill
13
13
  # The commands that act on a process or group, and that the CLI sends
14
14
  PROCESS_COMMANDS = [:start, :stop, :restart, :unmonitor, :status].freeze
15
15
 
16
+ # The commands that the daemon answers over its socket: the
17
+ # PROCESS_COMMANDS, and the version and log file that the CLI asks for
18
+ #
19
+ # @api private
20
+ DAEMON_COMMANDS = (PROCESS_COMMANDS + [:version, :log_file]).freeze
21
+
16
22
  attr_accessor :name, :logger, :base_dir, :socket, :pid_file, :kill_timeout, :groups, :work_queue, :pids_dir, :log_file
17
23
 
18
24
  # @!attribute [rw] name
@@ -241,11 +247,14 @@ module Bluepill
241
247
 
242
248
  # Return the daemon's version, which the CLI checks against its own
243
249
  #
244
- # @return [Module] the Version module
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.1.7"
245
254
  #
246
255
  # @api private
247
256
  def version
248
- Version
257
+ Version.to_s
249
258
  end
250
259
 
251
260
  protected
@@ -298,8 +307,8 @@ module Bluepill
298
307
  # The target is group:process and the process name may contain ':'
299
308
  command, *args = client.readline.strip.split(':', 3).reject(&:empty?)
300
309
  response = begin
301
- # An empty line leaves command nil, so public_send raises an error for the client
302
- mutex { public_send(command, *args) } # steep:ignore ArgumentTypeMismatch
310
+ method = daemon_command(command)
311
+ mutex { public_send(method, *args) }
303
312
  rescue StandardError => e
304
313
  e
305
314
  end
@@ -319,6 +328,25 @@ module Bluepill
319
328
  end
320
329
  end
321
330
 
331
+ # Return the one of the DAEMON_COMMANDS that a client's command names
332
+ #
333
+ # Anyone who can write to the socket can send any line, so only these
334
+ # commands may run, and not any other of the daemon's public methods.
335
+ #
336
+ # @param [String, nil] command the command, or nil for an empty line
337
+ #
338
+ # @raise [NoMethodError] if it names none of them
339
+ #
340
+ # @return [Symbol]
341
+ #
342
+ # @api private
343
+ def daemon_command(command)
344
+ # The backtrace is caller's lines, with no locations, so Ruby 3.1's
345
+ # error_highlight doesn't add a snippet of this file to the message
346
+ DAEMON_COMMANDS.detect { |name| name.to_s.eql?(command) } ||
347
+ raise(NoMethodError, "Unknown command `#{command}`", caller)
348
+ end
349
+
322
350
  # Start the daemon
323
351
  #
324
352
  # It stops a previous daemon for the application, clears journal locks
@@ -420,7 +448,7 @@ module Bluepill
420
448
  #
421
449
  # @api private
422
450
  def setup_logger_and_pids_dir
423
- self.logger = ProcessJournal.logger = Logger.new(log_file: log_file, stdout: foreground?).prefix_with(name)
451
+ self.logger = ProcessJournal.logger = Deprecation.logger = Logger.new(log_file: log_file, stdout: foreground?).prefix_with(name)
424
452
  setup_pids_dir
425
453
  rescue SystemCallError => e
426
454
  $stderr.puts("Failed to start bluepill: #{e}")
@@ -0,0 +1,48 @@
1
+ module Bluepill
2
+ # The clock that times ticks, checks, grace times and flapping
3
+ #
4
+ # The system clock can jump, when NTP corrects it or someone sets it, so
5
+ # a time between two readings of Time.now can come out too long, too
6
+ # short or below zero. The monotonic clock only counts up, one second a
7
+ # second.
8
+ #
9
+ # @api private
10
+ module Clock
11
+ # Return a reader of the monotonic clock, or of the system clock
12
+ #
13
+ # Process.clock_gettime, which Ruby 2.1 added, reads the monotonic clock.
14
+ # Ruby 1.9.3 and 2.0, and JRuby 1.7, don't have it, so they read the
15
+ # system clock, as bluepill 0.1.6 did. JRuby 9.0 has no :second unit, so
16
+ # it reads the clock in seconds, as a Float, and drops the fraction.
17
+ #
18
+ # @param [Module] process the module with clock_gettime, if Ruby has it
19
+ #
20
+ # @return [Proc] a reader of the time, in whole seconds
21
+ #
22
+ # @api private
23
+ def self.reader(process = ::Process)
24
+ if process.respond_to?(:clock_gettime)
25
+ -> { Integer(process.clock_gettime(::Process::CLOCK_MONOTONIC)) }
26
+ else
27
+ -> { Integer(Time.now) }
28
+ end
29
+ end
30
+
31
+ # The reader of this Ruby's clock, chosen once
32
+ #
33
+ # @api private
34
+ READER = reader
35
+
36
+ # Return the clock's time, in whole seconds
37
+ #
38
+ # The monotonic clock counts from an arbitrary point, such as when the
39
+ # machine booted, so a reading only means something next to another one.
40
+ #
41
+ # @return [Integer]
42
+ #
43
+ # @api private
44
+ def self.now
45
+ READER.call
46
+ end
47
+ end
48
+ end
@@ -81,42 +81,56 @@ module Bluepill
81
81
  # Run the check if it's due, and return the events to fire
82
82
  #
83
83
  # A check is due on its first run, and then every `every` seconds. A
84
- # run adds the value to the history and logs the history.
84
+ # run adds the value to the history and logs the history. A check that
85
+ # raises is logged and skipped until its next run, so one broken check
86
+ # doesn't stop the daemon.
85
87
  #
86
88
  # @param [Integer, nil] pid the process's pid
87
- # @param [Integer] tick_number the current time, in seconds
89
+ # @param [Integer] tick_number the time, from Clock.now
88
90
  #
89
91
  # @return [Array<Symbol>] the events to fire, empty unless the check
90
92
  # ran and failed often enough
91
93
  #
92
- # @raise [StandardError] whatever the check raised, other than a
93
- # System::PsError, after logging it
94
- #
95
94
  # @api private
96
- def run(pid, tick_number = Integer(Time.now))
95
+ def run(pid, tick_number = Clock.now)
97
96
  last_ran_at = @last_ran_at
98
97
  if last_ran_at.nil? || (last_ran_at + @every) <= tick_number
99
98
  @last_ran_at = tick_number
100
99
 
100
+ # A rescue here, not in a method of its own, so a check that runs
101
+ # makes no extra call
101
102
  begin
102
103
  value = @process_condition.run(pid, @include_children)
103
- rescue System::PsError => e
104
- # No data this time, so leave the history alone and check again next interval
105
- logger.warning("#{@name}: #{e}")
106
- return EMPTY_ARRAY
104
+ @history << HistoryValue.new(@process_condition.format_value(value), @process_condition.check(value))
105
+ logger.info(to_s)
106
+
107
+ return @fires if fired?
107
108
  rescue StandardError => e
108
- logger.err(e.backtrace)
109
- raise
109
+ check_failed(e)
110
110
  end
111
-
112
- @history << HistoryValue.new(@process_condition.format_value(value), @process_condition.check(value))
113
- logger.info(to_s)
114
-
115
- return @fires if fired?
116
111
  end
117
112
  EMPTY_ARRAY
118
113
  end
119
114
 
115
+ # Log an error the check raised, and skip the check until its next run
116
+ #
117
+ # A failed ps is a warning, since it says nothing about the check. Any
118
+ # other error is logged with its backtrace. Either way, the check adds
119
+ # nothing to its history and fires nothing this time.
120
+ #
121
+ # @param [StandardError] error what the check raised
122
+ #
123
+ # @return [void]
124
+ #
125
+ # @api private
126
+ def check_failed(error)
127
+ if error.is_a?(System::PsError)
128
+ logger.warning("#{@name}: #{error}")
129
+ else
130
+ Util.log_error(logger, "#{@name} check failed", error)
131
+ end
132
+ end
133
+
120
134
  # Forget the values the check read, as when the process changes state
121
135
  #
122
136
  # @return [Util::RotationalArray<HistoryValue>] the new, empty history
@@ -9,6 +9,20 @@ module Bluepill
9
9
  #
10
10
  # @api private
11
11
  class Controller
12
+ # The shell command that tails a log file ($1) through grep -E ($2)
13
+ #
14
+ # The path and the pattern are the shell's arguments, so they're never
15
+ # parsed as shell code, whatever characters they hold.
16
+ TAIL_COMMAND = 'tail -n 100 -f "$1" | grep -E "$2"'.freeze
17
+
18
+ # What the CLI says when the daemon runs another version of bluepill
19
+ OUT_OF_DATE = 'The running version of your daemon seems to be out of date.'.freeze
20
+
21
+ # What the CLI says to a daemon from before 0.1.7, which can't say
22
+ # which version it runs
23
+ UNKNOWN_VERSION = 'The running daemon is older than bluepill 0.1.7, so the CLI cannot check its version. ' \
24
+ 'Run bluepill load again to replace it.'.freeze
25
+
12
26
  attr_accessor :base_dir, :log_file, :sockets_dir, :pids_dir
13
27
 
14
28
  # @!attribute [rw] base_dir
@@ -94,15 +108,13 @@ module Bluepill
94
108
  puts "bluepilld[#{pid}] not running"
95
109
  end
96
110
  when :log
97
- log_file_location = send_to_daemon(application, :log_file)
98
- log_file_location = log_file if log_file_location.to_s.rstrip.empty?
111
+ log_file_location = send_to_daemon(application, :log_file).to_s
112
+ log_file_location = log_file.to_s if log_file_location.rstrip.empty?
99
113
 
100
114
  requested_pattern = args.first
101
- pattern = grep_pattern(application, requested_pattern)
102
-
103
- tail = "tail -n 100 -f #{log_file_location} | grep -E '#{pattern}'"
104
115
  puts "Tailing log for #{requested_pattern}..."
105
- Kernel.exec(tail)
116
+ # The path and the pattern are the shell's arguments, not its code
117
+ Kernel.exec('sh', '-c', TAIL_COMMAND, 'sh', log_file_location, grep_pattern(application, requested_pattern))
106
118
  when *Application::PROCESS_COMMANDS
107
119
  # these need to be sent to the daemon and the results printed out
108
120
  affected = send_to_daemon(application, command, *args)
@@ -213,6 +225,12 @@ module Bluepill
213
225
 
214
226
  # Abort unless an application's daemon runs this version of bluepill
215
227
  #
228
+ # A daemon answers with its version as a String. One from before 0.1.7
229
+ # answers with its Version module, which Marshal loads as the CLI's own,
230
+ # so it can't say which version it runs. The CLI warns about it and goes
231
+ # on, as it did before, so upgrading the gem doesn't stop the CLI from
232
+ # working with the daemon that's running.
233
+ #
216
234
  # @param [String] application the application's name
217
235
  #
218
236
  # @return [void]
@@ -220,9 +238,15 @@ module Bluepill
220
238
  # @api private
221
239
  def verify_version!(application)
222
240
  version = Socket.client_command(base_dir, application, 'version')
223
- abort("The running version of your daemon seems to be out of date.\nDaemon Version: #{version}, CLI Version: #{Version}") unless version.equal?(Version)
241
+ return if Version.to_s.eql?(version)
242
+
243
+ if version.instance_of?(String)
244
+ abort("#{OUT_OF_DATE}\nDaemon Version: #{version}, CLI Version: #{Version}")
245
+ else
246
+ $stderr.puts(UNKNOWN_VERSION)
247
+ end
224
248
  rescue ArgumentError
225
- abort('The running version of your daemon seems to be out of date.')
249
+ abort(OUT_OF_DATE)
226
250
  end
227
251
  end
228
252
  end
@@ -0,0 +1,74 @@
1
+ module Bluepill
2
+ # Warns, once each, about what a later version of bluepill will change
3
+ #
4
+ # A warning goes to stderr, where `bluepill load` shows it, since the pill
5
+ # file loads before the daemon detaches, and to bluepill's log once
6
+ # there is one. Each key warns once per process, so a warning raised
7
+ # while the daemon runs doesn't fill the log.
8
+ #
9
+ # @example
10
+ # Bluepill::Deprecation.warn(:pre_start_command, 'bluepill 0.2.0 ...')
11
+ #
12
+ # @api private
13
+ module Deprecation
14
+ @warned = {}
15
+ @mutex = Mutex.new
16
+ @logger = nil
17
+
18
+ class << self
19
+ # The logger that warnings also go to, once bluepill has one
20
+ #
21
+ # The application sets it when it creates its logger.
22
+ #
23
+ # @return [Logger, nil]
24
+ #
25
+ # @api private
26
+ attr_accessor :logger
27
+ end
28
+
29
+ # Warn about a change, unless this key has warned already
30
+ #
31
+ # @param [Object] key what the warning is about, such as
32
+ # :pre_start_command
33
+ # @param [String] message what will change, in which version, and what
34
+ # to do now
35
+ #
36
+ # @return [Boolean] whether it warned
37
+ #
38
+ # @api private
39
+ def self.warn(key, message)
40
+ return false unless first?(key)
41
+
42
+ line = "DEPRECATION: #{message}"
43
+ $stderr.puts(line)
44
+ log = logger
45
+ log.warning(line) if log
46
+ true
47
+ end
48
+
49
+ # Return whether a key is warning for the first time, and remember it
50
+ #
51
+ # @param [Object] key what the warning is about
52
+ #
53
+ # @return [Boolean] true the first time for each key
54
+ #
55
+ # @api private
56
+ def self.first?(key)
57
+ @mutex.synchronize do
58
+ return false if @warned.key?(key)
59
+
60
+ @warned[key] = true
61
+ end
62
+ end
63
+
64
+ # Forget the warnings given, and the logger, as between specs
65
+ #
66
+ # @return [void]
67
+ #
68
+ # @api private
69
+ def self.reset!
70
+ @mutex.synchronize { @warned.clear }
71
+ self.logger = nil
72
+ end
73
+ end
74
+ end
@@ -15,6 +15,37 @@ module Bluepill
15
15
  # @api private
16
16
  attr_reader :attributes
17
17
 
18
+ # The warning about a pre_start_command, which bluepill 0.2.0 limits
19
+ #
20
+ # @api private
21
+ PRE_START_COMMAND = 'bluepill 0.2.0 kills a pre_start_command that runs longer than hook_timeout, 30 seconds by default, ' \
22
+ "and starts the process even when the command can't run, where 0.1 waits for it however long it takes. " \
23
+ 'Set hook_timeout, which 0.1 ignores, if it can take longer.'.freeze
24
+
25
+ # The warning about a process with a uid and no gid, which bluepill
26
+ # 0.2.0 runs in the user's groups instead of root's
27
+ #
28
+ # @api private
29
+ UID_WITHOUT_GID = 'bluepill 0.2.0 runs a process that sets uid but not gid in the primary group and the other groups ' \
30
+ "of that user, where 0.1 keeps it in root's groups. Set gid and supplementary_groups to the groups it needs.".freeze
31
+
32
+ # The warning about a process with a uid and a gid, which bluepill 0.2.0
33
+ # also runs in the user's other groups
34
+ #
35
+ # @api private
36
+ UID_WITH_GID = 'bluepill 0.2.0 also runs a process that sets uid in every other group that user is in, ' \
37
+ 'where 0.1 gives it only its gid and supplementary_groups. ' \
38
+ "Make sure the user's groups don't give it access it shouldn't have.".freeze
39
+
40
+ # The warning about a process that monitors its children and runs as
41
+ # another user, whose children's commands bluepill 0.2.0 runs as that
42
+ # user too
43
+ #
44
+ # @api private
45
+ CHILDREN_USER = "bluepill 0.2.0 runs the commands of a monitor_children process's children, such as their stop_command, " \
46
+ "as the parent's uid, gid and supplementary_groups, where 0.1 runs them as root. " \
47
+ 'Make sure they work as that user, or run one that needs root with sudo.'.freeze
48
+
18
49
  # Only the keys matter
19
50
  @@process_keys = {} #: Hash[Array[String?], nil]
20
51
  @@pid_files = {} #: Hash[String, nil]
@@ -52,6 +83,7 @@ module Bluepill
52
83
 
53
84
  validate_process! process
54
85
  warn_unless_pid_known(process, default_pid_file)
86
+ warn_of_0_2_changes
55
87
  process.to_process
56
88
  end
57
89
 
@@ -211,6 +243,34 @@ module Bluepill
211
243
  $stderr.puts warning
212
244
  end
213
245
 
246
+ # Warn about what bluepill 0.2.0 does differently with the process
247
+ #
248
+ # @return [void]
249
+ #
250
+ # @api private
251
+ def warn_of_0_2_changes
252
+ Deprecation.warn(:pre_start_command, PRE_START_COMMAND) if attributes[:pre_start_command]
253
+ return unless attributes[:uid] || attributes[:gid] || attributes[:supplementary_groups]
254
+ # Bluepill only switches users and groups when it runs as root
255
+ return unless ::Process.euid.zero?
256
+
257
+ warn_of_0_2_groups if attributes[:uid]
258
+ Deprecation.warn(:monitor_children_user, CHILDREN_USER) if attributes[:monitor_children]
259
+ end
260
+
261
+ # Warn that bluepill 0.2.0 runs a process with a uid in the user's groups
262
+ #
263
+ # @return [void]
264
+ #
265
+ # @api private
266
+ def warn_of_0_2_groups
267
+ if attributes[:gid]
268
+ Deprecation.warn(:uid_with_gid, UID_WITH_GID)
269
+ else
270
+ Deprecation.warn(:uid_without_gid, UID_WITHOUT_GID)
271
+ end
272
+ end
273
+
214
274
  # Print a config error and exit with status 6
215
275
  #
216
276
  # @param [String] message the error
@@ -14,6 +14,12 @@ module Bluepill
14
14
  #
15
15
  # @api public
16
16
  class ProcessProxy
17
+ # The attributes that bluepill 0.2.0 adds, which it knows along with
18
+ # the ones bluepill 0.1 has
19
+ #
20
+ # @api private
21
+ ATTRIBUTES_ADDED_IN_0_2 = [:post_start_command, :pre_stop_command, :post_stop_command, :notify_command, :hook_timeout].freeze
22
+
17
23
  # Return the attributes that the block set, by name
18
24
  #
19
25
  # @return [Hash{Symbol => Object}] the attributes
@@ -80,10 +86,10 @@ module Bluepill
80
86
  case args.size
81
87
  when 1
82
88
  value, = args
83
- @attributes[attribute.chomp('=').to_sym] = value
89
+ set_attribute(attribute.chomp('=').to_sym, value)
84
90
  when 0
85
91
  if attribute.end_with?('!')
86
- @attributes[attribute.chomp('!').to_sym] = true
92
+ set_attribute(attribute.chomp('!').to_sym, true)
87
93
  elsif @attributes.key?(name)
88
94
  @attributes.fetch(name)
89
95
  else
@@ -149,6 +155,20 @@ module Bluepill
149
155
  @attributes[:child_process_block] = child_process_block
150
156
  end
151
157
 
158
+ # Return whether bluepill 0.2.0 knows a process attribute
159
+ #
160
+ # It knows a process's configurable attributes, the group, and the
161
+ # hooks it adds. It fails the config on any other.
162
+ #
163
+ # @param [Symbol] name the attribute's name
164
+ #
165
+ # @return [Boolean]
166
+ #
167
+ # @api private
168
+ def self.known_in_0_2?(name)
169
+ Process::CONFIGURABLE_ATTRIBUTES.include?(name) || name.eql?(:group) || ATTRIBUTES_ADDED_IN_0_2.include?(name)
170
+ end
171
+
152
172
  # Create the process that the block described
153
173
  #
154
174
  # @return [Process] the process
@@ -157,5 +177,24 @@ module Bluepill
157
177
  def to_process
158
178
  Process.new(@name, @watches, @attributes)
159
179
  end
180
+
181
+ private
182
+
183
+ # Set an attribute, and warn about one that bluepill 0.2.0 doesn't know
184
+ #
185
+ # @param [Symbol] key the attribute's name
186
+ # @param [Object] value its value
187
+ #
188
+ # @return [Object] the value
189
+ #
190
+ # @api private
191
+ def set_attribute(key, value)
192
+ unless self.class.known_in_0_2?(key)
193
+ message = "bluepill 0.2.0 fails the config on the process attribute '#{key}', which bluepill doesn't know, " \
194
+ 'where 0.1 ignores it. Remove it, or fix its name.'
195
+ Deprecation.warn(message, message)
196
+ end
197
+ @attributes[key] = value
198
+ end
160
199
  end
161
200
  end
data/lib/bluepill/dsl.rb CHANGED
@@ -26,8 +26,31 @@ module Bluepill
26
26
  # @api public
27
27
  def self.application(app_name, options = {}, &block)
28
28
  app_proxy = AppProxy.new(app_name, options)
29
+ warn_unsupported_ruby
29
30
  # instance_eval also passes the proxy to a block that takes an argument
30
31
  app_proxy.instance_eval(&block)
31
32
  app_proxy.app.load
32
33
  end
34
+
35
+ # Warn on a Ruby that bluepill 0.2 doesn't run on
36
+ #
37
+ # Bluepill 0.2.0 needs Ruby 2.0 or JRuby 9.0, and later 0.2 releases need
38
+ # Ruby 2.7 or JRuby 9.4. JRuby 1.7 can run Ruby 2.0 code, so it's told
39
+ # apart by its own version.
40
+ #
41
+ # @param [String] ruby_version the Ruby version, such as "1.9.3"
42
+ # @param [String, nil] jruby_version the JRuby version, such as "1.7.27",
43
+ # or nil on another Ruby
44
+ #
45
+ # @return [void]
46
+ #
47
+ # @api private
48
+ def self.warn_unsupported_ruby(ruby_version = RUBY_VERSION, jruby_version = defined?(JRUBY_VERSION) && JRUBY_VERSION)
49
+ # Only Ruby 1.9 and JRuby 1.7 have a major version of 1
50
+ return unless ruby_version.start_with?('1.') || (jruby_version && jruby_version.start_with?('1.'))
51
+
52
+ message = "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, so it won't run on Ruby #{ruby_version}" \
53
+ "#{" (JRuby #{jruby_version})" if jruby_version}. Stay on bluepill 0.1 until you upgrade Ruby."
54
+ Deprecation.warn(message, message)
55
+ end
33
56
  end