bluepill 0.2.1 → 0.2.5

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 (67) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +23 -1
  3. data/README.md +2 -2
  4. data/bin/bluepill +2 -2
  5. data/bluepill.gemspec +3 -1
  6. data/lib/bluepill/application/lifecycle.rb +3 -1
  7. data/lib/bluepill/application/listener.rb +4 -2
  8. data/lib/bluepill/application/previous_daemon.rb +2 -0
  9. data/lib/bluepill/application.rb +2 -0
  10. data/lib/bluepill/base_directory.rb +2 -0
  11. data/lib/bluepill/clock.rb +2 -0
  12. data/lib/bluepill/condition_watch.rb +2 -0
  13. data/lib/bluepill/controller/directory.rb +2 -0
  14. data/lib/bluepill/controller.rb +2 -0
  15. data/lib/bluepill/daemonize.rb +8 -10
  16. data/lib/bluepill/dsl/app_proxy.rb +2 -0
  17. data/lib/bluepill/dsl/process_factory/children.rb +2 -0
  18. data/lib/bluepill/dsl/process_factory/registry.rb +2 -0
  19. data/lib/bluepill/dsl/process_factory.rb +3 -1
  20. data/lib/bluepill/dsl/process_proxy.rb +2 -0
  21. data/lib/bluepill/dsl.rb +2 -0
  22. data/lib/bluepill/group.rb +2 -0
  23. data/lib/bluepill/logger.rb +3 -1
  24. data/lib/bluepill/pid_file.rb +2 -0
  25. data/lib/bluepill/process/attributes.rb +2 -0
  26. data/lib/bluepill/process/children.rb +2 -0
  27. data/lib/bluepill/process/pid.rb +2 -0
  28. data/lib/bluepill/process/state_machine.rb +2 -0
  29. data/lib/bluepill/process/transition.rb +2 -0
  30. data/lib/bluepill/process/transition_callbacks.rb +6 -6
  31. data/lib/bluepill/process/user_commands.rb +2 -0
  32. data/lib/bluepill/process/watches.rb +2 -0
  33. data/lib/bluepill/process.rb +2 -0
  34. data/lib/bluepill/process_commands/execution.rb +3 -1
  35. data/lib/bluepill/process_commands/hooks.rb +2 -0
  36. data/lib/bluepill/process_commands/stop_signals.rb +2 -0
  37. data/lib/bluepill/process_commands.rb +2 -0
  38. data/lib/bluepill/process_conditions/always_true.rb +2 -0
  39. data/lib/bluepill/process_conditions/below_threshold.rb +2 -0
  40. data/lib/bluepill/process_conditions/cpu_usage.rb +2 -0
  41. data/lib/bluepill/process_conditions/file_time.rb +2 -0
  42. data/lib/bluepill/process_conditions/http.rb +6 -2
  43. data/lib/bluepill/process_conditions/mem_usage.rb +5 -3
  44. data/lib/bluepill/process_conditions/process_condition.rb +2 -0
  45. data/lib/bluepill/process_conditions/running_time.rb +2 -0
  46. data/lib/bluepill/process_conditions/zombie_process.rb +3 -1
  47. data/lib/bluepill/process_conditions.rb +2 -0
  48. data/lib/bluepill/process_journal/cleanup.rb +6 -6
  49. data/lib/bluepill/process_journal/lock.rb +2 -0
  50. data/lib/bluepill/process_journal.rb +5 -3
  51. data/lib/bluepill/process_statistics.rb +3 -1
  52. data/lib/bluepill/socket.rb +6 -6
  53. data/lib/bluepill/system/command_setup.rb +3 -1
  54. data/lib/bluepill/system/commands.rb +2 -0
  55. data/lib/bluepill/system/daemon.rb +2 -0
  56. data/lib/bluepill/system/ps.rb +2 -0
  57. data/lib/bluepill/system/ps_table.rb +2 -0
  58. data/lib/bluepill/system.rb +4 -2
  59. data/lib/bluepill/trigger.rb +2 -0
  60. data/lib/bluepill/triggers/flapping.rb +2 -0
  61. data/lib/bluepill/units.rb +2 -0
  62. data/lib/bluepill/util/inflections.rb +2 -0
  63. data/lib/bluepill/util/levenshtein.rb +2 -0
  64. data/lib/bluepill/util/rotational_array.rb +2 -0
  65. data/lib/bluepill/version.rb +9 -7
  66. data/lib/bluepill.rb +2 -0
  67. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 24bda9b03c07276b7cd052d90f53e89cc2499b6317dead57a64b7a95a2fe9a82
4
- data.tar.gz: 39de75c1d40bf17038c37dbb5149feb4d41902c57b372d915720505504217924
3
+ metadata.gz: 5288f18359d2a2384f55d6b9d245b37182bda58cf9588301d02738caaaad631c
4
+ data.tar.gz: 1447ebe71f6ebe9be37ab4edd2ac3b695582b96995c2e3bb00ad1f20ec3a0361
5
5
  SHA512:
6
- metadata.gz: 2d177dd6ee49fde6b7eb69b98a01302c53950ef7564bbb2aeac680b671a272dc0b32abd7f3a341b779a5ce0bfc09ce57e6ba304cc5c4d46714cfb06cd20c7af4
7
- data.tar.gz: e607adb3667ee40d5b29343363d39e86b6c8d43835f0b48c58c7dad4c15465073dab130e5bab5fced3b266a05ac5de9065c9f8fe2d6fd23294396328757f4e38
6
+ metadata.gz: a837a60160c8aebb1dffc7d5206d30e79f9f84f2c4e65d6c879de0a94f9ffe7bb961c6aa0b0bdd7443fcdff60bb5ca8204a733058becf3fa5e2e320b70b458ad
7
+ data.tar.gz: 81fcacb8b9618c91dce85f862312e90c2a3bdd227500e795310d8d7646e001224bd27d37a36abb06a1b27ac4a4d77cca8ec5148d6b4ff12c09f2e53275d9ea37
data/CHANGELOG.md CHANGED
@@ -7,6 +7,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.2.5] - 2026-11-02
11
+
12
+ ### Changed
13
+
14
+ - The `zombie_process` check tests for `<defunct>` with `match?`, so each check makes one fewer object.
15
+
16
+ ### Removed
17
+
18
+ - **Breaking:** support for Ruby 2.3 and 2.4, and for JRuby 9.1, which runs Ruby 2.3 code. Bluepill 0.2.5 needs Ruby 2.5 or newer, or JRuby 9.2 or newer. Bluepill 0.2.3 still runs on them.
19
+
20
+ ## [0.2.3] - 2026-11-02
21
+
22
+ ### Changed
23
+
24
+ - Bluepill's string literals are frozen, so parsing `ps` each tick makes 10% fewer objects and takes 3% fewer instructions, and checks and `bluepill status` make a few fewer.
25
+
26
+ ### Removed
27
+
28
+ - **Breaking:** support for Ruby 2.1 and 2.2, and for JRuby 9.0, which runs Ruby 2.2 code. Bluepill 0.2.3 needs Ruby 2.3 or newer, or JRuby 9.1 or newer. Bluepill 0.2.1 still runs on them.
29
+
10
30
  ## [0.2.1] - 2026-11-02
11
31
 
12
32
  ### Removed
@@ -822,7 +842,9 @@ Initial release.
822
842
  - Added the `bluepill` CLI with the `load`, `status`, `start`, `stop`, `restart`, `unmonitor`, `quit` and `log` commands.
823
843
  - Added syslog logging.
824
844
 
825
- [unreleased]: https://github.com/bluepill-rb/bluepill/compare/v0.2.1...HEAD
845
+ [unreleased]: https://github.com/bluepill-rb/bluepill/compare/v0.2.5...HEAD
846
+ [0.2.5]: https://github.com/bluepill-rb/bluepill/compare/v0.2.3...v0.2.5
847
+ [0.2.3]: https://github.com/bluepill-rb/bluepill/compare/v0.2.1...v0.2.3
826
848
  [0.2.1]: https://github.com/bluepill-rb/bluepill/compare/v0.2.0...v0.2.1
827
849
  [0.2.0]: https://github.com/bluepill-rb/bluepill/compare/v0.1.6...v0.2.0
828
850
  [0.1.6]: https://github.com/bluepill-rb/bluepill/compare/v0.1.5...v0.1.6
data/README.md CHANGED
@@ -504,10 +504,10 @@ JRuby allows you to run bluepill only in the foreground.
504
504
  This library aims to support and is [tested against][ci] the following Ruby
505
505
  implementations:
506
506
 
507
- * Ruby 2.1 through 2.7
507
+ * Ruby 2.5 through 2.7
508
508
  * Ruby 3.0 through 3.4
509
509
  * Ruby 4.0
510
- * JRuby 9.0 through 9.4 (only in the foreground)
510
+ * JRuby 9.2 through 9.4 (only in the foreground)
511
511
  * JRuby 10.0 and 10.1 (only in the foreground)
512
512
 
513
513
  If something doesn't work on one of these interpreters, please open an issue.
data/bin/bluepill CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
  require "optparse"
3
4
  require "rbconfig"
4
5
  require "bluepill"
@@ -68,8 +69,7 @@ end
68
69
 
69
70
  APPLICATION_COMMANDS = %w[status start stop restart unmonitor quit log].freeze
70
71
 
71
- # Hash#slice needs Ruby 2.5
72
- controller = Bluepill::Controller.new(options.select { |key, _| %i[base_dir log_file].include?(key) })
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
data/bluepill.gemspec CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  lib = File.expand_path("lib", __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
  require "bluepill/version"
@@ -20,7 +22,7 @@ Gem::Specification.new do |spec|
20
22
  "rubygems_mfa_required" => "true"
21
23
  }
22
24
 
23
- spec.required_ruby_version = ">= 2.1"
25
+ spec.required_ruby_version = ">= 2.5"
24
26
 
25
27
  # sig has the RBS signatures, and the standard libraries they use in manifest.yaml
26
28
  spec.executables = %w[bluepill bpsv]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  class Application
3
5
  # Start the daemon, run it until a signal stops it, and clean up after
@@ -117,7 +119,7 @@ module Bluepill
117
119
  Signal.trap("INT", &terminator)
118
120
 
119
121
  Signal.trap("HUP") do
120
- logger.reopen if logger
122
+ logger&.reopen
121
123
  end
122
124
  end
123
125
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  class Application
3
5
  # Answer the commands that the CLI sends over the daemon's socket
@@ -19,7 +21,7 @@ module Bluepill
19
21
  # @api private
20
22
  def start_listener
21
23
  previous_thread = @listener_thread
22
- previous_thread.kill if previous_thread
24
+ previous_thread&.kill
23
25
  @listener_thread = Thread.new do
24
26
  loop do
25
27
  answer_next_client
@@ -115,7 +117,7 @@ module Bluepill
115
117
  #
116
118
  # @api private
117
119
  def close_client(client)
118
- client.close if client
120
+ client&.close
119
121
  rescue IOError
120
122
  # closed stream
121
123
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  class Application
3
5
  # Stop a daemon for the application that's still running, before
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bluepill/system"
2
4
  require "bluepill/process_journal"
3
5
  require "bluepill/base_directory"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  # The paths in bluepill's base directory
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  # The clock that times ticks, checks and grace times
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  # Runs a process's check every so often, and fires its events when the
3
5
  # check fails often enough
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  class Controller
3
5
  # Find the daemons in the base directory, and clean up after dead ones
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "fileutils"
2
4
  require "bluepill/system"
3
5
  require "bluepill/base_directory"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # The parts of the daemons gem that bluepill uses, which bluepill used to
2
4
  # get from blue-daemons, a fork of it. They're adapted from daemons'
3
5
  # lib/daemons/daemonize.rb, which carries this notice:
@@ -50,11 +52,9 @@ module Bluepill
50
52
  # @api private
51
53
  def self.safefork
52
54
  loop do
53
- begin
54
- return fork
55
- rescue Errno::EWOULDBLOCK
56
- sleep 5
57
- end
55
+ return fork
56
+ rescue Errno::EWOULDBLOCK
57
+ sleep 5
58
58
  end
59
59
  end
60
60
 
@@ -199,11 +199,9 @@ module Bluepill
199
199
  # @api private
200
200
  def self.close_fds
201
201
  (3..MAX_FD).each do |fd|
202
- begin
203
- IO.for_fd(fd).close
204
- rescue
205
- nil
206
- end
202
+ IO.for_fd(fd).close
203
+ rescue
204
+ nil
207
205
  end
208
206
  end
209
207
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  # The self of the block given to {Bluepill.application}
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  class ProcessFactory
3
5
  # Create the processes of the children that a process's factory finds
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  class ProcessFactory
3
5
  # The process names and pid files that an application's config has used
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bluepill/dsl/process_factory/children"
2
4
  require "bluepill/dsl/process_factory/registry"
3
5
 
@@ -188,7 +190,7 @@ module Bluepill
188
190
  # @api private
189
191
  def validate_stop_grace_time!(stop_signals, stop_grace_time)
190
192
  delays = stop_signals.select.with_index { |_, i| i.odd? }
191
- return unless stop_grace_time.nil? || stop_grace_time <= delays.inject(0, :+)
193
+ return unless stop_grace_time.nil? || stop_grace_time <= delays.sum
192
194
 
193
195
  config_error!("Config Error: Stop_grace_time should be greater than the sum of stop_signals delays!")
194
196
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bluepill/util/levenshtein"
2
4
 
3
5
  module Bluepill
data/lib/bluepill/dsl.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  # Load an application from a config file
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  # The processes of an application that share a group name
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  # Write bluepill's log, to syslog or a file, with prefixes
3
5
  #
@@ -87,7 +89,7 @@ module Bluepill
87
89
  # @return [void]
88
90
  # @api private
89
91
  LOG_METHODS.each_with_index do |method, priority|
90
- class_eval <<-RUBY, __FILE__, __LINE__ + 1
92
+ class_eval <<~RUBY, __FILE__, __LINE__ + 1
91
93
  def #{method}(msg, prefix = nil) # def emerg(msg, prefix = nil)
92
94
  # Below the log level, so dropped before anything is formatted
93
95
  return if #{priority} > @level # return if 0 > @level
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  # Read the pid file of a bluepill daemon
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  class Process
3
5
  # The options a config can set for a Process, and their defaults
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  class Process
3
5
  # Keeps a Process for each of a Process's children, when it monitors them
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  class Process
3
5
  # Finds, signals and forgets a Process's pid
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  class Process
3
5
  # Moves a Process between its states
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  class Process
3
5
  # A process's move from one state to another, as triggers and the
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  class Process
3
5
  # Runs what a Process does on its way from one state to another
@@ -62,12 +64,10 @@ module Bluepill
62
64
  # @api private
63
65
  def notify_triggers(transition)
64
66
  triggers.each do |trigger|
65
- begin
66
- trigger.notify(transition)
67
- rescue => e
68
- logger.err e.backtrace
69
- raise
70
- end
67
+ trigger.notify(transition)
68
+ rescue => e
69
+ logger.err e.backtrace
70
+ raise
71
71
  end
72
72
  end
73
73
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  class Process
3
5
  # Carries out the commands a user gives a Process from the command line
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  class Process
3
5
  # The checks that run on a Process every interval, such as its memory
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bluepill/system"
2
4
  require "bluepill/process_journal"
3
5
  require "bluepill/process_commands"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  module ProcessCommands
3
5
  # Runs a Process's commands as its user, in its working_dir, with its
@@ -79,7 +81,7 @@ module Bluepill
79
81
  result = System.execute_blocking(cmd, options)
80
82
  # The exit code is nil when a signal killed the command
81
83
  exit_code = result.fetch(:exit_code)
82
- return if exit_code && exit_code.zero?
84
+ return if exit_code&.zero?
83
85
 
84
86
  logger.warning "#{description} command execution returned non-zero exit code:"
85
87
  logger.warning result.inspect
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  module ProcessCommands
3
5
  # Runs the commands a Process has around its starts and stops, and on
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  module ProcessCommands
3
5
  # Stops a Process with its stop_signals: a signal, then a delay and a
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bluepill/process_commands/execution"
2
4
  require "bluepill/process_commands/hooks"
3
5
  require "bluepill/process_commands/stop_signals"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  module ProcessConditions
3
5
  # A check that always passes, for testing a config: `checks :always_true`
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  module ProcessConditions
3
5
  # Checks that a value a process reads is below a limit
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  module ProcessConditions
3
5
  # Checks a process's CPU usage, as a percentage
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  module ProcessConditions
3
5
  # Checks how long ago a file changed, in seconds
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "net/http"
2
4
  require "uri"
3
5
 
@@ -69,10 +71,12 @@ module Bluepill
69
71
  # @api private
70
72
  def check?(value)
71
73
  return false unless value.is_a?(@kind)
72
- return true unless @pattern
74
+
75
+ pattern = @pattern
76
+ return true unless pattern
73
77
 
74
78
  response = value #: Net::HTTPResponse
75
- !(@pattern =~ response.body).nil?
79
+ pattern.match?(response.body)
76
80
  end
77
81
 
78
82
  private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  module ProcessConditions
3
5
  # Checks a process's memory usage (its resident set size)
@@ -19,17 +21,17 @@ module Bluepill
19
21
  # How a value shows in the history: a number and its unit
20
22
  #
21
23
  # @api private
22
- FORMAT_STR = "%d%s".freeze
24
+ FORMAT_STR = "%d%s"
23
25
 
24
26
  # The unit of a value that shows in megabytes
25
27
  #
26
28
  # @api private
27
- MB_LABEL = "MB".freeze
29
+ MB_LABEL = "MB"
28
30
 
29
31
  # The unit of a value that shows in kilobytes
30
32
  #
31
33
  # @api private
32
- KB_LABEL = "KB".freeze
34
+ KB_LABEL = "KB"
33
35
 
34
36
  # Read the process's memory usage from the tick's ps table
35
37
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  module ProcessConditions
3
5
  # Checks something about a process, as one of a process's checks
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  module ProcessConditions
3
5
  # Checks how long a process has been running, in seconds
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  module ProcessConditions
3
5
  # Checks whether a process is a zombie, which ps shows as <defunct>
@@ -32,7 +34,7 @@ module Bluepill
32
34
  #
33
35
  # @api private
34
36
  def check?(value)
35
- (value =~ /<defunct>/).nil?
37
+ !value&.match?(/<defunct>/)
36
38
  end
37
39
  end
38
40
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  # The checks a process can run, named in a config by their underscored
3
5
  # class name, such as `checks :mem_usage`
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  module ProcessJournal
3
5
  # Kill what an earlier run left in a process's journals
@@ -187,12 +189,10 @@ module Bluepill
187
189
  def signal_journaled(signal, ids, kind)
188
190
  past, verb = signal.eql?("TERM") ? %w[Termed term] : %w[Killed kill]
189
191
  ids.each do |id|
190
- begin
191
- ::Process.kill(signal, kind.sign * id)
192
- logger.info("#{past} old #{kind.label} #{id}")
193
- rescue Errno::ESRCH
194
- logger.debug("Unable to #{verb} missing #{kind.label} #{id}")
195
- end
192
+ ::Process.kill(signal, kind.sign * id)
193
+ logger.info("#{past} old #{kind.label} #{id}")
194
+ rescue Errno::ESRCH
195
+ logger.debug("Unable to #{verb} missing #{kind.label} #{id}")
196
196
  end
197
197
  end
198
198
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  module ProcessJournal
3
5
  # Lock a journal while bluepill reads and writes it
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bluepill/system"
2
4
  require "bluepill/process_journal/cleanup"
3
5
  require "bluepill/process_journal/lock"
@@ -66,12 +68,12 @@ module Bluepill
66
68
  # A pid journal's kind
67
69
  #
68
70
  # @api private
69
- PID = Kind.new("pid".freeze, "process".freeze, "pids".freeze, 1).freeze
71
+ PID = Kind.new("pid", "process", "pids", 1).freeze
70
72
 
71
73
  # A process group journal's kind
72
74
  #
73
75
  # @api private
74
- PGID = Kind.new("pgid".freeze, "process group".freeze, "pgids".freeze, -1).freeze
76
+ PGID = Kind.new("pgid", "process group", "pgids", -1).freeze
75
77
 
76
78
  class << self
77
79
  # Return the logger the journal writes to
@@ -216,7 +218,7 @@ module Bluepill
216
218
  def self.journal_entries(filename)
217
219
  File.readlines(filename).collect do |line|
218
220
  id, started = line.split
219
- [id.to_i, started && started.to_i]
221
+ [id.to_i, started&.to_i]
220
222
  end
221
223
  end
222
224
 
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  # Keeps a process's last few events, which bluepill status shows
3
5
  #
4
6
  # @api private
5
7
  class ProcessStatistics
6
8
  # How status shows each event's time
7
- STRFTIME = "%m/%d/%Y %H:%M:%S".freeze
9
+ STRFTIME = "%m/%d/%Y %H:%M:%S"
8
10
 
9
11
  # How many events are kept
10
12
  EVENTS_TO_PERSIST = 10
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "socket"
2
4
  require "bluepill/base_directory"
3
5
 
@@ -44,12 +46,10 @@ module Bluepill
44
46
  def self.client_command(base_dir, name, command)
45
47
  res = nil
46
48
  MAX_ATTEMPTS.times do |current_attempt|
47
- begin
48
- res = send_command(base_dir, name, command)
49
- break
50
- rescue EOFError, Timeout::Error
51
- retry_or_abort(current_attempt)
52
- end
49
+ res = send_command(base_dir, name, command)
50
+ break
51
+ rescue EOFError, Timeout::Error
52
+ retry_or_abort(current_attempt)
53
53
  end
54
54
  res
55
55
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "etc"
2
4
 
3
5
  module Bluepill
@@ -22,7 +24,7 @@ module Bluepill
22
24
  working_dir = options[:working_dir]
23
25
  Dir.chdir(ENV["PWD"] = working_dir.to_s) if working_dir
24
26
  environment = options[:environment]
25
- environment.each { |key, value| ENV[key.to_s] = value.to_s } if environment
27
+ environment&.each { |key, value| ENV[key.to_s] = value.to_s }
26
28
  end
27
29
 
28
30
  # Switch to another user and groups, when bluepill runs as root
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "shellwords"
2
4
  require "bluepill/daemonize"
3
5
  require "bluepill/system/command_setup"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "shellwords"
2
4
  require "bluepill/daemonize"
3
5
  require "bluepill/system/command_setup"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bluepill/system/ps_table"
2
4
 
3
5
  module Bluepill
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  module System
3
5
  # A tick's table of processes, as ps listed them
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bluepill/system/ps"
2
4
  require "bluepill/system/commands"
3
5
 
@@ -19,7 +21,7 @@ module Bluepill
19
21
  # The mode that a daemon's stdout and stderr files are opened in
20
22
  #
21
23
  # @api private
22
- APPEND_MODE = "a".freeze
24
+ APPEND_MODE = "a"
23
25
 
24
26
  # Raised when ps could not be run, so there is no data for this tick
25
27
  #
@@ -152,7 +154,7 @@ module Bluepill
152
154
  # @api private
153
155
  def self.command(pid)
154
156
  row = ps_axu.row(pid)
155
- row.fetch(PsTable::COMMAND) if row
157
+ row&.fetch(PsTable::COMMAND)
156
158
  end
157
159
 
158
160
  # Delete a file if it exists
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  # Reacts to a process's state transitions, as one of a process's checks
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  # The triggers a process can have
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  # The durations and sizes a config writes, such as 10.seconds and
3
5
  # 100.megabytes, as plain numbers of seconds and bytes
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  # Small helpers bluepill keeps for itself
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  module Util
3
5
  # Return how many edits turn one string into another
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  # Small helpers for the rest of bluepill
3
5
  #
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Bluepill
2
4
  # The version of bluepill
3
5
  #
4
6
  # @example
5
- # Bluepill::Version.to_s # => "0.2.1"
7
+ # Bluepill::Version.to_s # => "0.2.5"
6
8
  #
7
9
  # @api public
8
10
  module Version
@@ -33,13 +35,13 @@ module Bluepill
33
35
  # Return the patch version
34
36
  #
35
37
  # @example
36
- # Bluepill::Version.patch # => 1
38
+ # Bluepill::Version.patch # => 5
37
39
  #
38
40
  # @return [Integer] the patch version
39
41
  #
40
42
  # @api public
41
43
  def self.patch
42
- 1
44
+ 5
43
45
  end
44
46
 
45
47
  # Return the pre-release version
@@ -56,7 +58,7 @@ module Bluepill
56
58
  # Return the version's parts by name
57
59
  #
58
60
  # @example
59
- # Bluepill::Version.to_h # => {major: 0, minor: 2, patch: 1, pre: nil}
61
+ # Bluepill::Version.to_h # => {major: 0, minor: 2, patch: 5, pre: nil}
60
62
  #
61
63
  # @return [Hash{Symbol => Integer, nil}] the major, minor, patch and
62
64
  # pre-release versions
@@ -74,7 +76,7 @@ module Bluepill
74
76
  # Return the version's parts, without a missing pre-release version
75
77
  #
76
78
  # @example
77
- # Bluepill::Version.to_a # => [0, 2, 1]
79
+ # Bluepill::Version.to_a # => [0, 2, 5]
78
80
  #
79
81
  # @return [Array<Integer>] the parts of the version
80
82
  #
@@ -86,9 +88,9 @@ module Bluepill
86
88
  # Return the version as a string
87
89
  #
88
90
  # @example
89
- # Bluepill::Version.to_s # => "0.2.1"
91
+ # Bluepill::Version.to_s # => "0.2.5"
90
92
  #
91
- # @return [String] the version, such as "0.2.1"
93
+ # @return [String] the version, such as "0.2.5"
92
94
  #
93
95
  # @api public
94
96
  def self.to_s
data/lib/bluepill.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rubygems"
2
4
 
3
5
  # A process monitor that keeps daemons running
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bluepill
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arya Asemanfar
@@ -116,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
116
  requirements:
117
117
  - - ">="
118
118
  - !ruby/object:Gem::Version
119
- version: '2.1'
119
+ version: '2.5'
120
120
  required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - ">="