bluepill 0.2.9 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +111 -2
- data/README.md +16 -13
- data/bin/bluepill +21 -8
- data/bluepill.gemspec +7 -2
- data/lib/bluepill/application/lifecycle.rb +48 -35
- data/lib/bluepill/application/listener.rb +2 -4
- data/lib/bluepill/application/previous_daemon.rb +12 -14
- data/lib/bluepill/application.rb +36 -30
- data/lib/bluepill/base_directory.rb +18 -20
- data/lib/bluepill/check_registry.rb +104 -0
- data/lib/bluepill/clock.rb +1 -3
- data/lib/bluepill/condition_watch.rb +46 -54
- data/lib/bluepill/controller/directory.rb +1 -3
- data/lib/bluepill/controller.rb +35 -37
- data/lib/bluepill/daemonize.rb +52 -0
- data/lib/bluepill/dsl/app_proxy.rb +68 -64
- data/lib/bluepill/dsl/attributes.rb +135 -0
- data/lib/bluepill/dsl/process_factory/child_factory.rb +83 -0
- data/lib/bluepill/dsl/process_factory/registry.rb +4 -26
- data/lib/bluepill/dsl/process_factory.rb +85 -84
- data/lib/bluepill/dsl/process_proxy.rb +80 -160
- data/lib/bluepill/dsl.rb +16 -15
- data/lib/bluepill/errors.rb +190 -0
- data/lib/bluepill/group.rb +14 -37
- data/lib/bluepill/logger.rb +65 -99
- data/lib/bluepill/process/attributes.rb +66 -32
- data/lib/bluepill/process/children.rb +6 -7
- data/lib/bluepill/process/pid.rb +43 -35
- data/lib/bluepill/process/state_machine.rb +15 -59
- data/lib/bluepill/process/stop_signals.rb +123 -0
- data/lib/bluepill/process/transition.rb +1 -3
- data/lib/bluepill/process/transition_callbacks.rb +2 -16
- data/lib/bluepill/process/triggers.rb +90 -0
- data/lib/bluepill/process/user_commands.rb +1 -1
- data/lib/bluepill/process/watches.rb +9 -23
- data/lib/bluepill/process.rb +55 -52
- data/lib/bluepill/process_commands/execution.rb +16 -24
- data/lib/bluepill/process_commands/hooks.rb +1 -31
- data/lib/bluepill/process_commands/stop_signals.rb +12 -17
- data/lib/bluepill/process_commands.rb +10 -8
- data/lib/bluepill/process_conditions/always_true.rb +2 -6
- data/lib/bluepill/process_conditions/below_threshold.rb +6 -8
- data/lib/bluepill/process_conditions/cpu_usage.rb +1 -4
- data/lib/bluepill/process_conditions/file_time.rb +8 -9
- data/lib/bluepill/process_conditions/http.rb +29 -67
- data/lib/bluepill/process_conditions/mem_usage.rb +7 -45
- data/lib/bluepill/process_conditions/process_condition.rb +29 -47
- data/lib/bluepill/process_conditions/zombie_process.rb +2 -6
- data/lib/bluepill/process_conditions.rb +5 -14
- data/lib/bluepill/process_journal/cleanup.rb +5 -53
- data/lib/bluepill/process_journal/config.rb +73 -0
- data/lib/bluepill/process_journal/entries.rb +128 -0
- data/lib/bluepill/process_journal/journal.rb +69 -0
- data/lib/bluepill/process_journal/kind.rb +60 -0
- data/lib/bluepill/process_journal/lock.rb +9 -4
- data/lib/bluepill/process_journal.rb +13 -324
- data/lib/bluepill/process_statistics.rb +3 -7
- data/lib/bluepill/socket.rb +19 -17
- data/lib/bluepill/system/command_options.rb +136 -0
- data/lib/bluepill/system/command_result.rb +73 -0
- data/lib/bluepill/system/command_setup.rb +3 -4
- data/lib/bluepill/system/command_spawn.rb +244 -0
- data/lib/bluepill/system/commands.rb +27 -40
- data/lib/bluepill/system/daemon.rb +97 -15
- data/lib/bluepill/system/files.rb +35 -0
- data/lib/bluepill/system/ps.rb +20 -17
- data/lib/bluepill/system/ps_table.rb +7 -9
- data/lib/bluepill/system/usage.rb +175 -0
- data/lib/bluepill/system.rb +7 -192
- data/lib/bluepill/trigger.rb +18 -69
- data/lib/bluepill/triggers/flapping.rb +12 -8
- data/lib/bluepill/units.rb +7 -21
- data/lib/bluepill/version.rb +16 -26
- data/lib/bluepill.rb +1 -1
- data/sig/bluepill/application.rbs +11 -12
- data/sig/bluepill/attributes.rbs +48 -0
- data/sig/bluepill/checks.rbs +40 -40
- data/sig/bluepill/dsl.rbs +100 -59
- data/sig/bluepill/errors.rbs +48 -0
- data/sig/bluepill/logger.rbs +15 -31
- data/sig/bluepill/process.rbs +39 -305
- data/sig/bluepill/process_commands.rbs +235 -0
- data/sig/bluepill/stop_signals.rbs +21 -0
- data/sig/bluepill/system.rbs +191 -101
- data/sig/bluepill/version.rbs +17 -0
- data/sig/bluepill.rbs +2 -17
- data/sig/manifest.yaml +1 -0
- metadata +22 -8
- data/lib/bluepill/deprecation/custom_checks.rb +0 -193
- data/lib/bluepill/deprecation/dsl.rb +0 -141
- data/lib/bluepill/deprecation/options.rb +0 -140
- data/lib/bluepill/deprecation.rb +0 -92
- data/lib/bluepill/dsl/process_factory/children.rb +0 -99
- data/sig/bluepill/deprecation.rbs +0 -87
data/lib/bluepill/system.rb
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "bluepill/system/ps"
|
|
4
|
+
require "bluepill/system/usage"
|
|
5
|
+
require "bluepill/system/files"
|
|
4
6
|
require "bluepill/system/commands"
|
|
5
7
|
|
|
6
8
|
module Bluepill
|
|
@@ -9,203 +11,16 @@ module Bluepill
|
|
|
9
11
|
# This represents the system that bluepill is running on. It memoizes
|
|
10
12
|
# the results of running ps each tick, so that every watch of every
|
|
11
13
|
# process doesn't fork a ps of its own. Running ps and reading its table
|
|
12
|
-
# is in System::Ps,
|
|
13
|
-
# System::
|
|
14
|
+
# is in System::Ps, asking about a process is in System::Usage, deleting
|
|
15
|
+
# files is in System::Files, and running commands is in System::Commands
|
|
16
|
+
# and System::Daemon. System only extends them.
|
|
14
17
|
#
|
|
15
18
|
# @api private
|
|
16
19
|
module System
|
|
17
20
|
extend Ps
|
|
21
|
+
extend Usage
|
|
22
|
+
extend Files
|
|
18
23
|
extend Commands
|
|
19
24
|
extend Daemon
|
|
20
|
-
|
|
21
|
-
# The mode that a daemon's stdout and stderr files are opened in
|
|
22
|
-
#
|
|
23
|
-
# @api private
|
|
24
|
-
APPEND_MODE = "a"
|
|
25
|
-
|
|
26
|
-
# Raised when ps could not be run, so there is no data for this tick
|
|
27
|
-
#
|
|
28
|
-
# @api private
|
|
29
|
-
class PsError < StandardError; end
|
|
30
|
-
|
|
31
|
-
# Return whether a process is running
|
|
32
|
-
#
|
|
33
|
-
# @param [Integer] pid the process's pid
|
|
34
|
-
#
|
|
35
|
-
# @return [Boolean] true if the process exists, even if bluepill may
|
|
36
|
-
# not signal it
|
|
37
|
-
#
|
|
38
|
-
# @api private
|
|
39
|
-
def self.pid_alive?(pid)
|
|
40
|
-
::Process.kill(0, pid)
|
|
41
|
-
true
|
|
42
|
-
rescue Errno::EPERM # no permission, but it is definitely alive
|
|
43
|
-
true
|
|
44
|
-
rescue
|
|
45
|
-
false # no such process (ESRCH), or no pid
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
# Return when a process started, in seconds since the epoch
|
|
49
|
-
#
|
|
50
|
-
# It's read from ps's elapsed time for the process, so it's accurate to
|
|
51
|
-
# about a second, and works wherever ps does.
|
|
52
|
-
#
|
|
53
|
-
# @param [Integer] pid the process's pid
|
|
54
|
-
#
|
|
55
|
-
# @return [Integer, nil] when it started, or nil if there's no such
|
|
56
|
-
# process
|
|
57
|
-
#
|
|
58
|
-
# @api private
|
|
59
|
-
def self.started_at(pid)
|
|
60
|
-
# ps says why on stderr when there's no such process
|
|
61
|
-
elapsed = IO.popen(["ps", "-o", "etime=", "-p", Integer(pid).to_s], err: File::NULL, &:read).rstrip
|
|
62
|
-
Integer(Time.now) - parse_elapsed_time(elapsed) unless elapsed.empty?
|
|
63
|
-
rescue SystemCallError
|
|
64
|
-
nil
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
# Return when the machine booted, in seconds since the epoch
|
|
68
|
-
#
|
|
69
|
-
# That's when its first process, pid 1, started. In a container, it's
|
|
70
|
-
# when the container started, which is when its pids start over.
|
|
71
|
-
#
|
|
72
|
-
# @return [Integer, nil] when it booted, or nil if ps can't tell
|
|
73
|
-
#
|
|
74
|
-
# @api private
|
|
75
|
-
def self.boot_time
|
|
76
|
-
started_at(1)
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
# Return a process's CPU usage, from this tick's ps table
|
|
80
|
-
#
|
|
81
|
-
# @param [Integer, nil] pid the process's pid
|
|
82
|
-
# @param [Boolean] include_children whether to add its descendants'
|
|
83
|
-
#
|
|
84
|
-
# @return [Float, nil] the percent of a CPU it uses, or nil if ps doesn't
|
|
85
|
-
# list it
|
|
86
|
-
#
|
|
87
|
-
# @raise [PsError] if ps could not be run this tick
|
|
88
|
-
#
|
|
89
|
-
# @api private
|
|
90
|
-
def self.cpu_usage(pid, include_children)
|
|
91
|
-
usage(pid, include_children, PsTable::PCPU)
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
# Return a process's resident memory, from this tick's ps table
|
|
95
|
-
#
|
|
96
|
-
# @param [Integer, nil] pid the process's pid
|
|
97
|
-
# @param [Boolean] include_children whether to add its descendants'
|
|
98
|
-
#
|
|
99
|
-
# @return [Float, nil] its resident memory in kilobytes, or nil if ps
|
|
100
|
-
# doesn't list it
|
|
101
|
-
#
|
|
102
|
-
# @raise [PsError] if ps could not be run this tick
|
|
103
|
-
#
|
|
104
|
-
# @api private
|
|
105
|
-
def self.memory_usage(pid, include_children)
|
|
106
|
-
usage(pid, include_children, PsTable::RSS)
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
# Return a column of a process's row, from this tick's ps table, as a Float
|
|
110
|
-
#
|
|
111
|
-
# @param [Integer, nil] pid the process's pid
|
|
112
|
-
# @param [Boolean] include_children whether to add its descendants'
|
|
113
|
-
# @param [Integer] column the column, PsTable::PCPU or PsTable::RSS
|
|
114
|
-
#
|
|
115
|
-
# @return [Float, nil] the process's value, and its descendants' if
|
|
116
|
-
# asked for, or nil if ps doesn't list it
|
|
117
|
-
#
|
|
118
|
-
# @raise [PsError] if ps could not be run this tick
|
|
119
|
-
#
|
|
120
|
-
# @api private
|
|
121
|
-
def self.usage(pid, include_children, column)
|
|
122
|
-
ps = ps_axu
|
|
123
|
-
row = ps.row(pid)
|
|
124
|
-
return unless row
|
|
125
|
-
|
|
126
|
-
used = row.fetch(column).to_f
|
|
127
|
-
include_children ? ps.sum(get_children(pid), column, used) : used
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
# Return how long a process has been running, from this tick's ps table
|
|
131
|
-
#
|
|
132
|
-
# @param [Integer, nil] pid the process's pid
|
|
133
|
-
#
|
|
134
|
-
# @return [Integer, nil] its running time in seconds, or nil if ps
|
|
135
|
-
# doesn't list it
|
|
136
|
-
#
|
|
137
|
-
# @raise [PsError] if ps could not be run this tick
|
|
138
|
-
#
|
|
139
|
-
# @api private
|
|
140
|
-
def self.running_time(pid)
|
|
141
|
-
row = ps_axu.row(pid)
|
|
142
|
-
parse_elapsed_time(row.fetch(PsTable::ETIME)) if row
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
# Return a process's command line, from this tick's ps table
|
|
146
|
-
#
|
|
147
|
-
# @param [Integer, nil] pid the process's pid
|
|
148
|
-
#
|
|
149
|
-
# @return [String, nil] its command and arguments, or nil if ps doesn't
|
|
150
|
-
# list it
|
|
151
|
-
#
|
|
152
|
-
# @raise [PsError] if ps could not be run this tick
|
|
153
|
-
#
|
|
154
|
-
# @api private
|
|
155
|
-
def self.command(pid)
|
|
156
|
-
row = ps_axu.row(pid)
|
|
157
|
-
row&.fetch(PsTable::COMMAND)
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
# Delete a file if it exists
|
|
161
|
-
#
|
|
162
|
-
# It tries three times when permission is denied, and then prints a
|
|
163
|
-
# warning instead of raising.
|
|
164
|
-
#
|
|
165
|
-
# @param [String, nil] filename the file's path
|
|
166
|
-
#
|
|
167
|
-
# @return [void]
|
|
168
|
-
#
|
|
169
|
-
# @api private
|
|
170
|
-
def self.delete_if_exists(filename)
|
|
171
|
-
tries = 0
|
|
172
|
-
|
|
173
|
-
begin
|
|
174
|
-
File.unlink(filename) if filename && File.exist?(filename)
|
|
175
|
-
rescue IOError, Errno::ENOENT
|
|
176
|
-
# Already gone, or another process removed it in between
|
|
177
|
-
rescue Errno::EACCES
|
|
178
|
-
retry if (tries += 1) < 3
|
|
179
|
-
$stderr.puts("Warning: permission denied trying to delete #{filename}")
|
|
180
|
-
end
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
# Watches run in their own threads, so only let one of them run ps per tick
|
|
184
|
-
#
|
|
185
|
-
# @api private
|
|
186
|
-
PS_MUTEX = Mutex.new
|
|
187
|
-
|
|
188
|
-
# No pids, which get_children returns for a process with no children
|
|
189
|
-
no_pids = [] #: Array[Integer]
|
|
190
|
-
NO_PIDS = no_pids.freeze
|
|
191
|
-
|
|
192
|
-
# Convert ps's elapsed time to seconds
|
|
193
|
-
#
|
|
194
|
-
# @param [String, nil] str an elapsed time, [[dd-]hh:]mm:ss
|
|
195
|
-
#
|
|
196
|
-
# @return [Integer] the seconds, or 0 if str isn't an elapsed time
|
|
197
|
-
#
|
|
198
|
-
# @api private
|
|
199
|
-
def self.parse_elapsed_time(str)
|
|
200
|
-
# [[dd-]hh:]mm:ss
|
|
201
|
-
match = /(?:(?:(\d+)-)?(\d\d):)?(\d\d):(\d\d)/.match(str)
|
|
202
|
-
if match
|
|
203
|
-
hours = (match[1].to_i * 24) + match[2].to_i
|
|
204
|
-
mins = (hours * 60) + match[3].to_i
|
|
205
|
-
(mins * 60) + match[4].to_i
|
|
206
|
-
else
|
|
207
|
-
0
|
|
208
|
-
end
|
|
209
|
-
end
|
|
210
25
|
end
|
|
211
26
|
end
|
data/lib/bluepill/trigger.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "bluepill/check_registry"
|
|
3
4
|
require "bluepill/util/log_error"
|
|
4
5
|
|
|
5
6
|
module Bluepill
|
|
@@ -7,7 +8,7 @@ module Bluepill
|
|
|
7
8
|
#
|
|
8
9
|
# A config names a trigger the way it names a check, by its underscored
|
|
9
10
|
# class name: `checks :flapping` makes a Triggers::Flapping. Subclasses
|
|
10
|
-
#
|
|
11
|
+
# add themselves to CheckRegistry by that name, and implement notify.
|
|
11
12
|
#
|
|
12
13
|
# @api private
|
|
13
14
|
class Trigger
|
|
@@ -17,9 +18,14 @@ module Bluepill
|
|
|
17
18
|
# @api private
|
|
18
19
|
HALT = :halt
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
# The methods a subclass must define
|
|
22
|
+
#
|
|
23
|
+
# @api private
|
|
24
|
+
REQUIRED_METHODS = %i[notify].freeze
|
|
21
25
|
|
|
22
|
-
#
|
|
26
|
+
# Add a subclass to the checks a config can name
|
|
27
|
+
#
|
|
28
|
+
# A config names it by its underscored name, such as :flapping.
|
|
23
29
|
#
|
|
24
30
|
# @param [Class] klass the subclass
|
|
25
31
|
#
|
|
@@ -28,42 +34,7 @@ module Bluepill
|
|
|
28
34
|
# @api private
|
|
29
35
|
def self.inherited(klass)
|
|
30
36
|
super
|
|
31
|
-
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
# Return the trigger class a config names
|
|
35
|
-
#
|
|
36
|
-
# @param [Symbol] name the trigger's underscored name, such as :flapping
|
|
37
|
-
#
|
|
38
|
-
# @return [Class, nil] the Trigger subclass, or nil when no trigger has
|
|
39
|
-
# that name (so the name is a check's)
|
|
40
|
-
#
|
|
41
|
-
# @api private
|
|
42
|
-
def self.[](name)
|
|
43
|
-
@implementations[name]
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
# Create a trigger, and warn about what 0.3.0 rejects in its class
|
|
47
|
-
#
|
|
48
|
-
# The trigger gets its options as keyword arguments, which an
|
|
49
|
-
# initialize that takes an options Hash gets as the Hash, so a custom
|
|
50
|
-
# trigger can take them either way, as bluepill 0.3.0's need keywords.
|
|
51
|
-
#
|
|
52
|
-
# @param [Process] process the process the trigger watches
|
|
53
|
-
# @param [Symbol] check_name the name the config gave it, such as
|
|
54
|
-
# :flapping
|
|
55
|
-
# @param [Logger, nil] logger the process's logger
|
|
56
|
-
# @param [Hash{Symbol => Object}] options the trigger's options
|
|
57
|
-
#
|
|
58
|
-
# @return [Trigger] the trigger
|
|
59
|
-
#
|
|
60
|
-
# @api private
|
|
61
|
-
def self.create(process, check_name, logger:, **options)
|
|
62
|
-
Deprecation.check_options(check_name, options, Deprecation::NO_OPTIONS)
|
|
63
|
-
Deprecation.check_trigger_class(self)
|
|
64
|
-
trigger = new(process, **options, logger: logger) #: untyped
|
|
65
|
-
Deprecation.check_logger(trigger, logger)
|
|
66
|
-
trigger
|
|
37
|
+
CheckRegistry.add(klass, Trigger, REQUIRED_METHODS)
|
|
67
38
|
end
|
|
68
39
|
|
|
69
40
|
# Return the process the trigger watches
|
|
@@ -80,22 +51,6 @@ module Bluepill
|
|
|
80
51
|
# @api private
|
|
81
52
|
attr_reader :logger
|
|
82
53
|
|
|
83
|
-
# Set the logger the trigger writes to
|
|
84
|
-
#
|
|
85
|
-
# The process sets it. Bluepill 0.3.0 removes it, so it warns when code
|
|
86
|
-
# outside bluepill calls it.
|
|
87
|
-
#
|
|
88
|
-
# @param [Logger, nil] logger the process's logger
|
|
89
|
-
#
|
|
90
|
-
# @return [void]
|
|
91
|
-
#
|
|
92
|
-
# @api private
|
|
93
|
-
def logger=(logger)
|
|
94
|
-
locations = caller_locations(0, 2) #: Array[Thread::Backtrace::Location]
|
|
95
|
-
Deprecation.check_logger_writer(self, locations.last)
|
|
96
|
-
@logger = logger
|
|
97
|
-
end
|
|
98
|
-
|
|
99
54
|
# Return the events the trigger scheduled, each with its thread
|
|
100
55
|
#
|
|
101
56
|
# Read them under the lock, since their threads remove them as they
|
|
@@ -110,15 +65,16 @@ module Bluepill
|
|
|
110
65
|
# Create a trigger for a process
|
|
111
66
|
#
|
|
112
67
|
# @param [Process] process the process to watch
|
|
113
|
-
# @param [
|
|
114
|
-
# :logger
|
|
68
|
+
# @param [Logger, nil] logger the process's logger
|
|
115
69
|
#
|
|
116
70
|
# @return [void]
|
|
117
71
|
#
|
|
72
|
+
# @raise [ArgumentError] for an option that no trigger takes
|
|
73
|
+
#
|
|
118
74
|
# @api private
|
|
119
|
-
def initialize(process,
|
|
75
|
+
def initialize(process, logger: nil)
|
|
120
76
|
self.process = process
|
|
121
|
-
|
|
77
|
+
@logger = logger
|
|
122
78
|
@mutex = Mutex.new
|
|
123
79
|
@scheduled_events = []
|
|
124
80
|
# The reason the trigger gives the process for what it dispatches,
|
|
@@ -131,9 +87,7 @@ module Bluepill
|
|
|
131
87
|
# @return [void]
|
|
132
88
|
#
|
|
133
89
|
# @api private
|
|
134
|
-
def reset!
|
|
135
|
-
cancel_all_events
|
|
136
|
-
end
|
|
90
|
+
def reset! = cancel_all_events
|
|
137
91
|
|
|
138
92
|
# React to a state transition, before it happens
|
|
139
93
|
#
|
|
@@ -144,9 +98,7 @@ module Bluepill
|
|
|
144
98
|
# @raise [RuntimeError] unless a subclass implements it
|
|
145
99
|
#
|
|
146
100
|
# @api private
|
|
147
|
-
def notify(_transition)
|
|
148
|
-
raise "Implement in subclass"
|
|
149
|
-
end
|
|
101
|
+
def notify(_transition) = raise("Implement in subclass")
|
|
150
102
|
|
|
151
103
|
# Send an event to the process, with the trigger's name as the reason
|
|
152
104
|
#
|
|
@@ -155,10 +107,7 @@ module Bluepill
|
|
|
155
107
|
# @return [Boolean] whether the process made the transition
|
|
156
108
|
#
|
|
157
109
|
# @api private
|
|
158
|
-
def dispatch!(event)
|
|
159
|
-
Deprecation.check_trigger_event(self, event)
|
|
160
|
-
process.dispatch!(event, @reason)
|
|
161
|
-
end
|
|
110
|
+
def dispatch!(event) = process.dispatch!(event, @reason)
|
|
162
111
|
|
|
163
112
|
# Dispatch an event after a delay, in a thread of its own
|
|
164
113
|
#
|
|
@@ -55,18 +55,22 @@ module Bluepill
|
|
|
55
55
|
# Create the trigger for a process
|
|
56
56
|
#
|
|
57
57
|
# @param [Process] process the process to watch
|
|
58
|
-
# @param [
|
|
59
|
-
#
|
|
58
|
+
# @param [Integer] times how many starts and restarts are flapping
|
|
59
|
+
# @param [Numeric] within the seconds they must happen within
|
|
60
|
+
# @param [Numeric] retry_in the seconds to wait before starting the
|
|
61
|
+
# process again, or 0 to leave it unmonitored
|
|
62
|
+
# @param [Hash{Symbol => Object}] options the other options, with
|
|
63
|
+
# :logger
|
|
60
64
|
#
|
|
61
65
|
# @return [void]
|
|
62
66
|
#
|
|
63
67
|
# @api private
|
|
64
|
-
def initialize(process,
|
|
65
|
-
@times =
|
|
66
|
-
@within =
|
|
67
|
-
@retry_in =
|
|
68
|
-
@timeline = Util::RotationalArray.new(
|
|
69
|
-
super
|
|
68
|
+
def initialize(process, times: 5, within: 1, retry_in: 5, **options)
|
|
69
|
+
@times = times
|
|
70
|
+
@within = within
|
|
71
|
+
@retry_in = retry_in
|
|
72
|
+
@timeline = Util::RotationalArray.new(times)
|
|
73
|
+
super(process, **options)
|
|
70
74
|
end
|
|
71
75
|
|
|
72
76
|
# Record a start or a restart, and check whether the process flaps
|
data/lib/bluepill/units.rb
CHANGED
|
@@ -36,9 +36,7 @@ module Bluepill
|
|
|
36
36
|
# @return [Numeric] the number itself
|
|
37
37
|
#
|
|
38
38
|
# @api public
|
|
39
|
-
def seconds
|
|
40
|
-
self
|
|
41
|
-
end
|
|
39
|
+
def seconds = self
|
|
42
40
|
alias_method :second, :seconds
|
|
43
41
|
|
|
44
42
|
# Return this many minutes, in seconds
|
|
@@ -49,9 +47,7 @@ module Bluepill
|
|
|
49
47
|
# @return [Numeric] the number of seconds
|
|
50
48
|
#
|
|
51
49
|
# @api public
|
|
52
|
-
def minutes
|
|
53
|
-
self * MINUTE
|
|
54
|
-
end
|
|
50
|
+
def minutes = self * MINUTE
|
|
55
51
|
alias_method :minute, :minutes
|
|
56
52
|
|
|
57
53
|
# Return this many hours, in seconds
|
|
@@ -62,9 +58,7 @@ module Bluepill
|
|
|
62
58
|
# @return [Numeric] the number of seconds
|
|
63
59
|
#
|
|
64
60
|
# @api public
|
|
65
|
-
def hours
|
|
66
|
-
self * HOUR
|
|
67
|
-
end
|
|
61
|
+
def hours = self * HOUR
|
|
68
62
|
alias_method :hour, :hours
|
|
69
63
|
|
|
70
64
|
# Return this many days, in seconds
|
|
@@ -75,9 +69,7 @@ module Bluepill
|
|
|
75
69
|
# @return [Numeric] the number of seconds
|
|
76
70
|
#
|
|
77
71
|
# @api public
|
|
78
|
-
def days
|
|
79
|
-
self * DAY
|
|
80
|
-
end
|
|
72
|
+
def days = self * DAY
|
|
81
73
|
alias_method :day, :days
|
|
82
74
|
|
|
83
75
|
# Return this many kilobytes, in bytes
|
|
@@ -88,9 +80,7 @@ module Bluepill
|
|
|
88
80
|
# @return [Numeric] the number of bytes
|
|
89
81
|
#
|
|
90
82
|
# @api public
|
|
91
|
-
def kilobytes
|
|
92
|
-
self * KILOBYTE
|
|
93
|
-
end
|
|
83
|
+
def kilobytes = self * KILOBYTE
|
|
94
84
|
alias_method :kilobyte, :kilobytes
|
|
95
85
|
|
|
96
86
|
# Return this many megabytes, in bytes
|
|
@@ -101,9 +91,7 @@ module Bluepill
|
|
|
101
91
|
# @return [Numeric] the number of bytes
|
|
102
92
|
#
|
|
103
93
|
# @api public
|
|
104
|
-
def megabytes
|
|
105
|
-
self * MEGABYTE
|
|
106
|
-
end
|
|
94
|
+
def megabytes = self * MEGABYTE
|
|
107
95
|
alias_method :megabyte, :megabytes
|
|
108
96
|
|
|
109
97
|
# Return this many gigabytes, in bytes
|
|
@@ -114,9 +102,7 @@ module Bluepill
|
|
|
114
102
|
# @return [Numeric] the number of bytes
|
|
115
103
|
#
|
|
116
104
|
# @api public
|
|
117
|
-
def gigabytes
|
|
118
|
-
self * GIGABYTE
|
|
119
|
-
end
|
|
105
|
+
def gigabytes = self * GIGABYTE
|
|
120
106
|
alias_method :gigabyte, :gigabytes
|
|
121
107
|
end
|
|
122
108
|
end
|
data/lib/bluepill/version.rb
CHANGED
|
@@ -4,7 +4,7 @@ module Bluepill
|
|
|
4
4
|
# The version of bluepill
|
|
5
5
|
#
|
|
6
6
|
# @example
|
|
7
|
-
# Bluepill::Version.to_s # => "0.2
|
|
7
|
+
# Bluepill::Version.to_s # => "0.3.2"
|
|
8
8
|
#
|
|
9
9
|
# @api public
|
|
10
10
|
module Version
|
|
@@ -16,33 +16,27 @@ module Bluepill
|
|
|
16
16
|
# @return [Integer] the major version
|
|
17
17
|
#
|
|
18
18
|
# @api public
|
|
19
|
-
def self.major
|
|
20
|
-
0
|
|
21
|
-
end
|
|
19
|
+
def self.major = 0
|
|
22
20
|
|
|
23
21
|
# Return the minor version
|
|
24
22
|
#
|
|
25
23
|
# @example
|
|
26
|
-
# Bluepill::Version.minor # =>
|
|
24
|
+
# Bluepill::Version.minor # => 3
|
|
27
25
|
#
|
|
28
26
|
# @return [Integer] the minor version
|
|
29
27
|
#
|
|
30
28
|
# @api public
|
|
31
|
-
def self.minor
|
|
32
|
-
2
|
|
33
|
-
end
|
|
29
|
+
def self.minor = 3
|
|
34
30
|
|
|
35
31
|
# Return the patch version
|
|
36
32
|
#
|
|
37
33
|
# @example
|
|
38
|
-
# Bluepill::Version.patch # =>
|
|
34
|
+
# Bluepill::Version.patch # => 2
|
|
39
35
|
#
|
|
40
36
|
# @return [Integer] the patch version
|
|
41
37
|
#
|
|
42
38
|
# @api public
|
|
43
|
-
def self.patch
|
|
44
|
-
9
|
|
45
|
-
end
|
|
39
|
+
def self.patch = 2
|
|
46
40
|
|
|
47
41
|
# Return the pre-release version
|
|
48
42
|
#
|
|
@@ -58,7 +52,7 @@ module Bluepill
|
|
|
58
52
|
# Return the version's parts by name
|
|
59
53
|
#
|
|
60
54
|
# @example
|
|
61
|
-
# Bluepill::Version.to_h # => {major: 0, minor:
|
|
55
|
+
# Bluepill::Version.to_h # => {major: 0, minor: 3, patch: 2, pre: nil}
|
|
62
56
|
#
|
|
63
57
|
# @return [Hash{Symbol => Integer, nil}] the major, minor, patch and
|
|
64
58
|
# pre-release versions
|
|
@@ -66,35 +60,31 @@ module Bluepill
|
|
|
66
60
|
# @api public
|
|
67
61
|
def self.to_h
|
|
68
62
|
{
|
|
69
|
-
major
|
|
70
|
-
minor
|
|
71
|
-
patch
|
|
72
|
-
pre:
|
|
63
|
+
major:,
|
|
64
|
+
minor:,
|
|
65
|
+
patch:,
|
|
66
|
+
pre:
|
|
73
67
|
}
|
|
74
68
|
end
|
|
75
69
|
|
|
76
70
|
# Return the version's parts, without a missing pre-release version
|
|
77
71
|
#
|
|
78
72
|
# @example
|
|
79
|
-
# Bluepill::Version.to_a # => [0,
|
|
73
|
+
# Bluepill::Version.to_a # => [0, 3, 2]
|
|
80
74
|
#
|
|
81
75
|
# @return [Array<Integer>] the parts of the version
|
|
82
76
|
#
|
|
83
77
|
# @api public
|
|
84
|
-
def self.to_a
|
|
85
|
-
to_h.values.compact
|
|
86
|
-
end
|
|
78
|
+
def self.to_a = to_h.values.compact
|
|
87
79
|
|
|
88
80
|
# Return the version as a string
|
|
89
81
|
#
|
|
90
82
|
# @example
|
|
91
|
-
# Bluepill::Version.to_s # => "0.2
|
|
83
|
+
# Bluepill::Version.to_s # => "0.3.2"
|
|
92
84
|
#
|
|
93
|
-
# @return [String] the version, such as "0.2
|
|
85
|
+
# @return [String] the version, such as "0.3.2"
|
|
94
86
|
#
|
|
95
87
|
# @api public
|
|
96
|
-
def self.to_s
|
|
97
|
-
to_a.join(".")
|
|
98
|
-
end
|
|
88
|
+
def self.to_s = to_a.join(".")
|
|
99
89
|
end
|
|
100
90
|
end
|
data/lib/bluepill.rb
CHANGED
|
@@ -33,10 +33,10 @@ require "timeout"
|
|
|
33
33
|
require "logger"
|
|
34
34
|
|
|
35
35
|
require "bluepill/clock"
|
|
36
|
-
require "bluepill/deprecation"
|
|
37
36
|
require "bluepill/units"
|
|
38
37
|
require "bluepill/util/inflections"
|
|
39
38
|
|
|
39
|
+
require "bluepill/errors"
|
|
40
40
|
require "bluepill/dsl/process_proxy"
|
|
41
41
|
require "bluepill/dsl/process_factory"
|
|
42
42
|
require "bluepill/dsl/app_proxy"
|
|
@@ -19,11 +19,11 @@ module Bluepill
|
|
|
19
19
|
attr_accessor pids_dir: String
|
|
20
20
|
attr_accessor log_file: String?
|
|
21
21
|
|
|
22
|
-
@foreground: bool
|
|
23
|
-
@log_level:
|
|
22
|
+
@foreground: bool
|
|
23
|
+
@log_level: Symbol | String
|
|
24
24
|
@mutex: Thread::Mutex
|
|
25
25
|
|
|
26
|
-
def initialize: (String name, ?
|
|
26
|
+
def initialize: (String name, ?foreground: bool, ?log_file: String?, ?log_level: Symbol | String, ?base_dir: String?, ?kill_timeout: Integer) -> void
|
|
27
27
|
|
|
28
28
|
def foreground?: () -> bool
|
|
29
29
|
|
|
@@ -51,7 +51,6 @@ module Bluepill
|
|
|
51
51
|
|
|
52
52
|
private
|
|
53
53
|
|
|
54
|
-
# Logs an error that stopped the daemon at crit, with its backtrace
|
|
55
54
|
def log_crash: (StandardError error) -> void
|
|
56
55
|
|
|
57
56
|
def send_to_process_or_group: (Symbol method, String? group_name, String? process_name) -> Array[String]
|
|
@@ -111,7 +110,7 @@ module Bluepill
|
|
|
111
110
|
def synchronize: [T] () { () -> T } -> T
|
|
112
111
|
end
|
|
113
112
|
|
|
114
|
-
@log_level:
|
|
113
|
+
@log_level: Symbol | String
|
|
115
114
|
@running: bool
|
|
116
115
|
|
|
117
116
|
# Ruby's protected methods are private in RBS
|
|
@@ -122,8 +121,6 @@ module Bluepill
|
|
|
122
121
|
|
|
123
122
|
def become_process_group_leader: () -> void
|
|
124
123
|
|
|
125
|
-
def daemonize_and_trap_signals: () -> void
|
|
126
|
-
|
|
127
124
|
def serve: () -> void
|
|
128
125
|
|
|
129
126
|
def run: () -> void
|
|
@@ -132,10 +129,12 @@ module Bluepill
|
|
|
132
129
|
|
|
133
130
|
def setup_signal_traps: () -> void
|
|
134
131
|
|
|
135
|
-
def
|
|
132
|
+
def setup_logger: () -> void
|
|
136
133
|
|
|
137
134
|
def setup_pids_dir: () -> void
|
|
138
135
|
|
|
136
|
+
def unwritable: (SystemCallError error) -> StartupError
|
|
137
|
+
|
|
139
138
|
def write_pid_file: () -> void
|
|
140
139
|
end
|
|
141
140
|
|
|
@@ -172,7 +171,7 @@ module Bluepill
|
|
|
172
171
|
attr_accessor log_file: String?
|
|
173
172
|
attr_reader base_directory: BaseDirectory
|
|
174
173
|
|
|
175
|
-
def initialize: (
|
|
174
|
+
def initialize: (base_dir: String, ?log_file: String?) -> void
|
|
176
175
|
|
|
177
176
|
def handle_command: (String application, String | Symbol command, *String args) -> void
|
|
178
177
|
|
|
@@ -191,8 +190,6 @@ module Bluepill
|
|
|
191
190
|
|
|
192
191
|
def print_affected: (String | Symbol command, Array[String] affected) -> void
|
|
193
192
|
|
|
194
|
-
def exit_with_daemon_error: (Exception error) -> void
|
|
195
|
-
|
|
196
193
|
def verify_version!: (String application) -> void
|
|
197
194
|
|
|
198
195
|
# Finds the daemons in the base directory, for Controller only
|
|
@@ -226,6 +223,8 @@ module Bluepill
|
|
|
226
223
|
|
|
227
224
|
def pids_dir: () -> String
|
|
228
225
|
|
|
226
|
+
def journals_dir: () -> String
|
|
227
|
+
|
|
229
228
|
def socket_file: (String app) -> String
|
|
230
229
|
|
|
231
230
|
def pid_file: (String app) -> String
|
|
@@ -252,7 +251,7 @@ module Bluepill
|
|
|
252
251
|
# Returns the daemon's response, unmarshaled
|
|
253
252
|
def self.send_command: (String base_dir, String name, String command) -> untyped
|
|
254
253
|
|
|
255
|
-
def self.
|
|
254
|
+
def self.retry_or_give_up: (Integer current_attempt) -> void
|
|
256
255
|
|
|
257
256
|
def self.server: (String base_dir, String name) -> UNIXServer
|
|
258
257
|
|