bluepill 0.1.6 → 0.2.1
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 +61 -1
- data/CONTRIBUTING.md +2 -2
- data/README.md +106 -9
- data/bin/bluepill +25 -30
- data/bluepill.gemspec +21 -28
- data/lib/bluepill/application/lifecycle.rb +166 -0
- data/lib/bluepill/application/listener.rb +124 -0
- data/lib/bluepill/application/previous_daemon.rb +81 -0
- data/lib/bluepill/application.rb +56 -254
- data/lib/bluepill/base_directory.rb +93 -0
- data/lib/bluepill/clock.rb +25 -0
- data/lib/bluepill/condition_watch.rb +136 -58
- data/lib/bluepill/controller/directory.rb +59 -0
- data/lib/bluepill/controller.rb +99 -94
- data/lib/bluepill/daemonize.rb +234 -0
- data/lib/bluepill/dsl/app_proxy.rb +30 -6
- data/lib/bluepill/dsl/process_factory/children.rb +71 -0
- data/lib/bluepill/dsl/process_factory/registry.rb +69 -0
- data/lib/bluepill/dsl/process_factory.rb +81 -92
- data/lib/bluepill/dsl/process_proxy.rb +109 -21
- data/lib/bluepill/group.rb +187 -78
- data/lib/bluepill/logger.rb +139 -48
- data/lib/bluepill/pid_file.rb +23 -0
- data/lib/bluepill/process/attributes.rb +379 -0
- data/lib/bluepill/process/children.rb +70 -0
- data/lib/bluepill/process/pid.rb +154 -0
- data/lib/bluepill/process/state_machine.rb +196 -0
- data/lib/bluepill/process/transition.rb +45 -0
- data/lib/bluepill/process/transition_callbacks.rb +101 -0
- data/lib/bluepill/process/user_commands.rb +71 -0
- data/lib/bluepill/process/watches.rb +141 -0
- data/lib/bluepill/process.rb +60 -657
- data/lib/bluepill/process_commands/execution.rb +89 -0
- data/lib/bluepill/process_commands/hooks.rb +186 -0
- data/lib/bluepill/process_commands/stop_signals.rb +114 -0
- data/lib/bluepill/process_commands.rb +106 -174
- data/lib/bluepill/process_conditions/always_true.rb +1 -1
- data/lib/bluepill/process_conditions/below_threshold.rb +36 -0
- data/lib/bluepill/process_conditions/cpu_usage.rb +1 -25
- data/lib/bluepill/process_conditions/file_time.rb +4 -5
- data/lib/bluepill/process_conditions/http.rb +52 -24
- data/lib/bluepill/process_conditions/mem_usage.rb +9 -22
- data/lib/bluepill/process_conditions/process_condition.rb +34 -3
- data/lib/bluepill/process_conditions/running_time.rb +1 -25
- data/lib/bluepill/process_conditions/zombie_process.rb +1 -1
- data/lib/bluepill/process_conditions.rb +3 -2
- data/lib/bluepill/process_journal/cleanup.rb +200 -0
- data/lib/bluepill/process_journal/lock.rb +106 -0
- data/lib/bluepill/process_journal.rb +126 -233
- data/lib/bluepill/process_statistics.rb +2 -2
- data/lib/bluepill/socket.rb +60 -20
- data/lib/bluepill/system/command_setup.rb +98 -0
- data/lib/bluepill/system/commands.rb +219 -248
- data/lib/bluepill/system/daemon.rb +161 -0
- data/lib/bluepill/system/ps.rb +85 -0
- data/lib/bluepill/system/ps_table.rb +163 -0
- data/lib/bluepill/system.rb +45 -126
- data/lib/bluepill/trigger.rb +52 -26
- data/lib/bluepill/triggers/flapping.rb +8 -16
- data/lib/bluepill/units.rb +126 -0
- data/lib/bluepill/util/inflections.rb +34 -0
- data/lib/bluepill/util/levenshtein.rb +53 -0
- data/lib/bluepill/util/rotational_array.rb +1 -1
- data/lib/bluepill/version.rb +13 -12
- data/lib/bluepill.rb +33 -36
- data/sig/bluepill/application.rbs +257 -0
- data/sig/bluepill/checks.rbs +203 -0
- data/sig/bluepill/dsl.rbs +126 -0
- data/sig/bluepill/logger.rbs +104 -0
- data/sig/bluepill/process.rbs +542 -0
- data/sig/bluepill/system.rbs +316 -0
- data/sig/bluepill.rbs +50 -871
- metadata +40 -45
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
module Bluepill
|
|
2
|
+
# The daemon: it holds the groups of processes and serves commands from
|
|
3
|
+
# bluepill's socket
|
|
4
|
+
class Application
|
|
5
|
+
include Listener
|
|
6
|
+
include Lifecycle
|
|
7
|
+
include PreviousDaemon
|
|
8
|
+
|
|
9
|
+
PROCESS_COMMANDS: Array[Symbol]
|
|
10
|
+
DAEMON_COMMANDS: Array[Symbol]
|
|
11
|
+
|
|
12
|
+
attr_accessor name: String
|
|
13
|
+
attr_accessor logger: Logger
|
|
14
|
+
attr_accessor base_dir: String
|
|
15
|
+
attr_accessor socket: UNIXServer?
|
|
16
|
+
attr_accessor pid_file: String
|
|
17
|
+
attr_accessor kill_timeout: Integer
|
|
18
|
+
attr_accessor groups: Hash[String?, Group]
|
|
19
|
+
attr_accessor pids_dir: String
|
|
20
|
+
attr_accessor log_file: String?
|
|
21
|
+
|
|
22
|
+
@foreground: bool?
|
|
23
|
+
@log_level: (Symbol | String)?
|
|
24
|
+
@mutex: Thread::Mutex
|
|
25
|
+
|
|
26
|
+
def initialize: (String name, ?Hash[Symbol, untyped] options) -> void
|
|
27
|
+
|
|
28
|
+
def foreground?: () -> bool
|
|
29
|
+
|
|
30
|
+
def synchronize: [T] () { () -> T } -> T
|
|
31
|
+
|
|
32
|
+
def load: () -> void
|
|
33
|
+
|
|
34
|
+
# The PROCESS_COMMANDS, which return the affected processes, or the
|
|
35
|
+
# status lines for status
|
|
36
|
+
def start: (?String? group_name, ?String? process_name) -> Array[String]
|
|
37
|
+
|
|
38
|
+
def stop: (?String? group_name, ?String? process_name) -> Array[String]
|
|
39
|
+
|
|
40
|
+
def restart: (?String? group_name, ?String? process_name) -> Array[String]
|
|
41
|
+
|
|
42
|
+
def unmonitor: (?String? group_name, ?String? process_name) -> Array[String]
|
|
43
|
+
|
|
44
|
+
def status: (?String? group_name, ?String? process_name) -> Array[String]
|
|
45
|
+
|
|
46
|
+
def add_process: (Process process, ?_ToS? group_name) -> Array[Process]
|
|
47
|
+
|
|
48
|
+
def version: () -> singleton(Version)
|
|
49
|
+
|
|
50
|
+
# Ruby's protected methods are private in RBS
|
|
51
|
+
|
|
52
|
+
private
|
|
53
|
+
|
|
54
|
+
def send_to_process_or_group: (Symbol method, String? group_name, String? process_name) -> Array[String]
|
|
55
|
+
|
|
56
|
+
def send_to_groups: (Symbol method, *String args) -> Array[String]
|
|
57
|
+
|
|
58
|
+
def setup_base_dir: (String? dir) -> void
|
|
59
|
+
|
|
60
|
+
def default_base_dir: () -> String
|
|
61
|
+
|
|
62
|
+
# Answers the CLI's commands on the socket, for Application only
|
|
63
|
+
module Listener : Object, _Host
|
|
64
|
+
# What Listener uses from Application
|
|
65
|
+
interface _Host
|
|
66
|
+
%a{pure} def socket: () -> UNIXServer?
|
|
67
|
+
%a{pure} def logger: () -> Logger
|
|
68
|
+
def synchronize: [T] () { () -> T } -> T
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
@listener_thread: Thread?
|
|
72
|
+
|
|
73
|
+
# Ruby's protected methods are private in RBS
|
|
74
|
+
|
|
75
|
+
private
|
|
76
|
+
|
|
77
|
+
def start_listener: () -> Thread
|
|
78
|
+
|
|
79
|
+
def answer_next_client: () -> void
|
|
80
|
+
|
|
81
|
+
def answer_command: (UNIXSocket client) -> void
|
|
82
|
+
|
|
83
|
+
def command_result: (String? command, Array[String] args) -> untyped
|
|
84
|
+
|
|
85
|
+
def daemon_command: (String? command) -> Symbol
|
|
86
|
+
|
|
87
|
+
def log_listener_error: (StandardError error) -> void
|
|
88
|
+
|
|
89
|
+
def close_client: (UNIXSocket? client) -> void
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# Starts, runs and cleans up after the daemon, for Application only
|
|
93
|
+
module Lifecycle : Object, _Host, Listener, PreviousDaemon
|
|
94
|
+
# What Lifecycle uses from Application
|
|
95
|
+
interface _Host
|
|
96
|
+
%a{pure} def name: () -> String
|
|
97
|
+
%a{pure} def logger: () -> Logger
|
|
98
|
+
def logger=: (Logger logger) -> Logger
|
|
99
|
+
%a{pure} def base_dir: () -> String
|
|
100
|
+
%a{pure} def socket: () -> UNIXServer?
|
|
101
|
+
def socket=: (UNIXServer? socket) -> UNIXServer?
|
|
102
|
+
%a{pure} def pid_file: () -> String
|
|
103
|
+
%a{pure} def pids_dir: () -> String
|
|
104
|
+
%a{pure} def log_file: () -> String?
|
|
105
|
+
%a{pure} def kill_timeout: () -> Integer
|
|
106
|
+
%a{pure} def groups: () -> Hash[String?, Group]
|
|
107
|
+
def foreground?: () -> bool
|
|
108
|
+
def synchronize: [T] () { () -> T } -> T
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
@log_level: (Symbol | String)?
|
|
112
|
+
@running: bool
|
|
113
|
+
|
|
114
|
+
# Ruby's protected methods are private in RBS
|
|
115
|
+
|
|
116
|
+
private
|
|
117
|
+
|
|
118
|
+
def start_server: () -> void
|
|
119
|
+
|
|
120
|
+
def become_process_group_leader: () -> void
|
|
121
|
+
|
|
122
|
+
def daemonize_and_trap_signals: () -> void
|
|
123
|
+
|
|
124
|
+
def serve: () -> void
|
|
125
|
+
|
|
126
|
+
def run: () -> void
|
|
127
|
+
|
|
128
|
+
def cleanup: () -> void
|
|
129
|
+
|
|
130
|
+
def setup_signal_traps: () -> void
|
|
131
|
+
|
|
132
|
+
def setup_logger_and_pids_dir: () -> void
|
|
133
|
+
|
|
134
|
+
def setup_pids_dir: () -> void
|
|
135
|
+
|
|
136
|
+
def write_pid_file: () -> void
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
# Stops a previous daemon for the application, for Application only
|
|
140
|
+
module PreviousDaemon : Object, _Host
|
|
141
|
+
# What PreviousDaemon uses from Application
|
|
142
|
+
interface _Host
|
|
143
|
+
%a{pure} def pid_file: () -> String
|
|
144
|
+
%a{pure} def kill_timeout: () -> Integer
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
# Ruby's protected methods are private in RBS
|
|
148
|
+
|
|
149
|
+
private
|
|
150
|
+
|
|
151
|
+
def kill_previous_bluepill: () -> void
|
|
152
|
+
|
|
153
|
+
def interrupt_previous_bluepill: () -> Integer?
|
|
154
|
+
|
|
155
|
+
def previous_bluepill_pid: () -> Integer?
|
|
156
|
+
|
|
157
|
+
def wait_for_previous_bluepill: (Integer previous_pid) -> void
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
# Runs the bluepill commands, and sends them to the daemon over its socket
|
|
162
|
+
class Controller
|
|
163
|
+
include Directory
|
|
164
|
+
|
|
165
|
+
attr_accessor base_dir: String
|
|
166
|
+
attr_accessor log_file: String?
|
|
167
|
+
attr_reader base_directory: BaseDirectory
|
|
168
|
+
|
|
169
|
+
def initialize: (Hash[Symbol, untyped] options) -> void
|
|
170
|
+
|
|
171
|
+
def handle_command: (String application, String | Symbol command, *String args) -> void
|
|
172
|
+
|
|
173
|
+
# Returns what the daemon responds with, which is unmarshaled from the socket
|
|
174
|
+
def send_to_daemon: (String application, String | Symbol command, *String args) -> untyped
|
|
175
|
+
|
|
176
|
+
def grep_pattern: (String application, ?String? query) -> String
|
|
177
|
+
|
|
178
|
+
private
|
|
179
|
+
|
|
180
|
+
def quit_daemon: (String application) -> void
|
|
181
|
+
|
|
182
|
+
def tail_log: (String application, String? requested_pattern) -> void
|
|
183
|
+
|
|
184
|
+
def send_process_command: (String application, String | Symbol command, *String args) -> void
|
|
185
|
+
|
|
186
|
+
def print_affected: (String | Symbol command, Array[String] affected) -> void
|
|
187
|
+
|
|
188
|
+
def exit_with_daemon_error: (Exception error) -> void
|
|
189
|
+
|
|
190
|
+
def verify_version!: (String application) -> void
|
|
191
|
+
|
|
192
|
+
# Finds the daemons in the base directory, for Controller only
|
|
193
|
+
module Directory : _Host
|
|
194
|
+
# What Directory uses from Controller
|
|
195
|
+
interface _Host
|
|
196
|
+
def base_directory: () -> BaseDirectory
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
def running_applications: () -> Array[String]
|
|
200
|
+
|
|
201
|
+
private
|
|
202
|
+
|
|
203
|
+
def cleanup_bluepill_directory: () -> void
|
|
204
|
+
|
|
205
|
+
def pid_for: (String app) -> (Integer | false)
|
|
206
|
+
|
|
207
|
+
def setup_dir_structure: () -> void
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
# The paths of the sockets and pid files in bluepill's base directory
|
|
212
|
+
class BaseDirectory
|
|
213
|
+
SOCKET_EXTENSION: String
|
|
214
|
+
|
|
215
|
+
attr_reader path: String
|
|
216
|
+
|
|
217
|
+
def initialize: (String path) -> void
|
|
218
|
+
|
|
219
|
+
def sockets_dir: () -> String
|
|
220
|
+
|
|
221
|
+
def pids_dir: () -> String
|
|
222
|
+
|
|
223
|
+
def socket_file: (String app) -> String
|
|
224
|
+
|
|
225
|
+
def pid_file: (String app) -> String
|
|
226
|
+
|
|
227
|
+
def process_pids_dir: (String app) -> String
|
|
228
|
+
|
|
229
|
+
def socket_names: () -> Array[String]
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
# Reads a daemon's pid file
|
|
233
|
+
module PidFile
|
|
234
|
+
def self.read: (String path) -> Integer?
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
module Socket
|
|
238
|
+
TIMEOUT: Integer
|
|
239
|
+
MAX_ATTEMPTS: Integer
|
|
240
|
+
|
|
241
|
+
def self.client: [T] (String base_dir, String name) { (UNIXSocket socket) -> T } -> T
|
|
242
|
+
|
|
243
|
+
# Returns the daemon's response, unmarshaled
|
|
244
|
+
def self.client_command: (String base_dir, String name, String command) -> untyped
|
|
245
|
+
|
|
246
|
+
# Returns the daemon's response, unmarshaled
|
|
247
|
+
def self.send_command: (String base_dir, String name, String command) -> untyped
|
|
248
|
+
|
|
249
|
+
def self.retry_or_abort: (Integer current_attempt) -> void
|
|
250
|
+
|
|
251
|
+
def self.server: (String base_dir, String name) -> UNIXServer
|
|
252
|
+
|
|
253
|
+
def self.replace_stale_socket: (String path) -> UNIXServer
|
|
254
|
+
|
|
255
|
+
def self.socket_path: (String base_dir, String name) -> String
|
|
256
|
+
end
|
|
257
|
+
end
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
module Bluepill
|
|
2
|
+
# Runs a process condition every so often, and fires its events when the
|
|
3
|
+
# check fails often enough
|
|
4
|
+
class ConditionWatch
|
|
5
|
+
# A value the watch got, and whether it passed the check
|
|
6
|
+
class HistoryValue < Struct[_ToS]
|
|
7
|
+
attr_accessor value: _ToS
|
|
8
|
+
attr_accessor critical: bool
|
|
9
|
+
|
|
10
|
+
def self.new: (_ToS value, bool critical) -> HistoryValue
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
EMPTY_ARRAY: Array[Symbol]
|
|
14
|
+
WATCH_KEYS: Array[Symbol]
|
|
15
|
+
|
|
16
|
+
attr_reader logger: Logger
|
|
17
|
+
attr_accessor name: Symbol
|
|
18
|
+
|
|
19
|
+
@fires: Array[Symbol]
|
|
20
|
+
@every: Integer
|
|
21
|
+
# How many values in the window must fail for the watch to fire
|
|
22
|
+
@required: Integer
|
|
23
|
+
# How many of the last values the watch remembers
|
|
24
|
+
@window: Integer
|
|
25
|
+
@include_children: bool
|
|
26
|
+
@history: Util::RotationalArray[HistoryValue]
|
|
27
|
+
@process_condition: ProcessConditions::ProcessCondition[untyped]
|
|
28
|
+
@last_ran_at: Integer?
|
|
29
|
+
|
|
30
|
+
def initialize: (Symbol name, ?Hash[Symbol, untyped] options) -> void
|
|
31
|
+
|
|
32
|
+
def create_condition: (Hash[Symbol, untyped] options) -> void
|
|
33
|
+
|
|
34
|
+
# Sets the logger of the watch and its condition
|
|
35
|
+
def logger=: (Logger logger) -> void
|
|
36
|
+
|
|
37
|
+
# Returns the events to fire
|
|
38
|
+
def due?: (Integer tick_number) -> bool
|
|
39
|
+
def run: (Integer? pid, ?Integer tick_number) -> Array[Symbol]
|
|
40
|
+
|
|
41
|
+
def run_check: (Integer? pid) -> Array[Symbol]
|
|
42
|
+
|
|
43
|
+
def check_failed: (StandardError error) -> Array[Symbol]
|
|
44
|
+
|
|
45
|
+
def clear_history!: () -> Util::RotationalArray[HistoryValue]
|
|
46
|
+
|
|
47
|
+
def to_s: () -> String
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Reacts to a process's state transitions. Subclasses register themselves
|
|
51
|
+
# by their underscored name.
|
|
52
|
+
class Trigger
|
|
53
|
+
HALT: :halt
|
|
54
|
+
|
|
55
|
+
self.@implementations: Hash[Symbol, singleton(Trigger)]
|
|
56
|
+
|
|
57
|
+
def self.inherited: (singleton(Trigger) klass) -> void
|
|
58
|
+
|
|
59
|
+
def self.[]: %a{implicitly-returns-nil} (Symbol name) -> singleton(Trigger)
|
|
60
|
+
|
|
61
|
+
attr_accessor process: Process
|
|
62
|
+
attr_accessor logger: Logger
|
|
63
|
+
attr_reader scheduled_events: Array[[Symbol, Thread]]
|
|
64
|
+
|
|
65
|
+
@reason: String
|
|
66
|
+
|
|
67
|
+
def initialize: (Process process, ?Hash[Symbol, untyped] options) -> void
|
|
68
|
+
|
|
69
|
+
def reset!: () -> void
|
|
70
|
+
|
|
71
|
+
def notify: (_Transition transition) -> void
|
|
72
|
+
|
|
73
|
+
def dispatch!: (Symbol event) -> bool
|
|
74
|
+
|
|
75
|
+
def schedule_event: (Symbol event, seconds delay) -> Thread
|
|
76
|
+
|
|
77
|
+
def run_scheduled_event: (Symbol event, seconds delay) -> void
|
|
78
|
+
|
|
79
|
+
def cancel_all_events: () -> void
|
|
80
|
+
|
|
81
|
+
private
|
|
82
|
+
|
|
83
|
+
attr_reader mutex: Thread::Mutex
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
module Triggers
|
|
87
|
+
# Unmonitors a process that starts or restarts too often, and starts it
|
|
88
|
+
# again later
|
|
89
|
+
class Flapping < Trigger
|
|
90
|
+
TRIGGER_STATES: Array[Symbol]
|
|
91
|
+
|
|
92
|
+
attr_accessor times: Integer
|
|
93
|
+
attr_accessor within: Integer
|
|
94
|
+
attr_accessor retry_in: Integer
|
|
95
|
+
attr_reader timeline: Util::RotationalArray[Integer]
|
|
96
|
+
|
|
97
|
+
def initialize: (Process process, ?Hash[Symbol, untyped] options) -> void
|
|
98
|
+
|
|
99
|
+
def notify: (_Transition transition) -> void
|
|
100
|
+
|
|
101
|
+
def reset!: () -> void
|
|
102
|
+
|
|
103
|
+
def check_flapping: () -> void
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
module ProcessConditions
|
|
108
|
+
def self.[]: (Symbol | String name) -> singleton(ProcessCondition)
|
|
109
|
+
|
|
110
|
+
# Checks something about a process. V is the type of value that run
|
|
111
|
+
# returns and check tests.
|
|
112
|
+
class ProcessCondition[V]
|
|
113
|
+
@options: Hash[Symbol, untyped]
|
|
114
|
+
|
|
115
|
+
# The watch's logger
|
|
116
|
+
attr_accessor logger: Logger?
|
|
117
|
+
|
|
118
|
+
def initialize: (?Hash[Symbol, untyped] options) -> void
|
|
119
|
+
|
|
120
|
+
def run: (Integer? pid, boolish include_children) -> V
|
|
121
|
+
|
|
122
|
+
# Whether the value is fine
|
|
123
|
+
def check?: (V value) -> bool
|
|
124
|
+
def check: (V value) -> bool
|
|
125
|
+
|
|
126
|
+
def format_value: (V value) -> V
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
class AlwaysTrue < ProcessCondition[Integer]
|
|
130
|
+
def run: (Integer? pid, boolish include_children) -> Integer
|
|
131
|
+
|
|
132
|
+
def check?: (Integer value) -> true
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# Checks that a value is below the check's below: limit. V is the type
|
|
136
|
+
# of value that run returns.
|
|
137
|
+
class BelowThreshold[V < Numeric] < ProcessCondition[V]
|
|
138
|
+
@below: Numeric
|
|
139
|
+
|
|
140
|
+
def check?: (V value) -> bool
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
class CpuUsage < BelowThreshold[Float]
|
|
144
|
+
def run: (Integer? pid, boolish include_children) -> Float
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
# Seconds since the file changed, or the error that stopped bluepill
|
|
148
|
+
# from finding out
|
|
149
|
+
class FileTime < BelowThreshold[Float]
|
|
150
|
+
@filename: String
|
|
151
|
+
|
|
152
|
+
def run: (Integer? pid, boolish include_children) -> (Float | StandardError | nil)
|
|
153
|
+
|
|
154
|
+
def check?: (Float | StandardError | nil value) -> bool
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
class Http < ProcessCondition[Net::HTTPResponse | StandardError]
|
|
158
|
+
@uri: URI::HTTP
|
|
159
|
+
@kind: Class
|
|
160
|
+
@pattern: Regexp?
|
|
161
|
+
@open_timeout: Integer
|
|
162
|
+
@read_timeout: Integer
|
|
163
|
+
|
|
164
|
+
def run: (Integer? pid, boolish include_children) -> (Net::HTTPResponse | StandardError)
|
|
165
|
+
|
|
166
|
+
def check?: (Net::HTTPResponse | StandardError value) -> bool
|
|
167
|
+
|
|
168
|
+
private
|
|
169
|
+
|
|
170
|
+
def response_class: (untyped kind) -> Class
|
|
171
|
+
|
|
172
|
+
def new_session: () -> Net::HTTP
|
|
173
|
+
|
|
174
|
+
def hide_net_http_bug: [T] () { () -> T } -> T
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
# Memory usage in kilobytes
|
|
178
|
+
class MemUsage < BelowThreshold[Float]
|
|
179
|
+
MB: Integer
|
|
180
|
+
FORMAT_STR: String
|
|
181
|
+
MB_LABEL: String
|
|
182
|
+
KB_LABEL: String
|
|
183
|
+
|
|
184
|
+
def run: (Integer? pid, boolish include_children) -> Float
|
|
185
|
+
|
|
186
|
+
def check?: (Float value) -> bool
|
|
187
|
+
|
|
188
|
+
def format_value: (Float value) -> String
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
# Seconds since the process started
|
|
192
|
+
class RunningTime < BelowThreshold[Integer]
|
|
193
|
+
def run: (Integer? pid, boolish include_children) -> Integer
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
# The process's command line, which says <defunct> for a zombie
|
|
197
|
+
class ZombieProcess < ProcessCondition[String?]
|
|
198
|
+
def run: (Integer? pid, boolish include_children) -> String?
|
|
199
|
+
|
|
200
|
+
def check?: (String? value) -> bool
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
end
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
module Bluepill
|
|
2
|
+
# self in an application block
|
|
3
|
+
class AppProxy
|
|
4
|
+
APP_ATTRIBUTES: Array[Symbol]
|
|
5
|
+
|
|
6
|
+
attr_accessor working_dir: String?
|
|
7
|
+
attr_accessor uid: String?
|
|
8
|
+
attr_accessor gid: String?
|
|
9
|
+
attr_accessor supplementary_groups: Array[String]?
|
|
10
|
+
attr_accessor environment: Hash[_ToS, _ToS]?
|
|
11
|
+
attr_accessor auto_start: bool?
|
|
12
|
+
attr_accessor notify_command: String?
|
|
13
|
+
attr_reader app: Application
|
|
14
|
+
|
|
15
|
+
@registry: ProcessFactory::Registry
|
|
16
|
+
|
|
17
|
+
def initialize: (_ToS app_name, Hash[Symbol, untyped] options) -> void
|
|
18
|
+
|
|
19
|
+
# The block runs with self set to the ProcessProxy, and also gets it as
|
|
20
|
+
# an argument
|
|
21
|
+
def process: (String process_name) { (ProcessProxy process) [self: ProcessProxy] -> void } -> Array[Process]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Builds processes from a process block in the config
|
|
25
|
+
class ProcessFactory
|
|
26
|
+
include Children
|
|
27
|
+
|
|
28
|
+
@process_block: process_block
|
|
29
|
+
@registry: Registry
|
|
30
|
+
|
|
31
|
+
attr_reader attributes: Hash[Symbol, untyped]
|
|
32
|
+
|
|
33
|
+
def initialize: (Hash[Symbol, untyped] attributes, process_block process_block, ?Registry registry) -> void
|
|
34
|
+
|
|
35
|
+
# The process, and the group its block set
|
|
36
|
+
def create_process: (String name, String pids_dir) -> [Process, untyped]
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
|
|
40
|
+
def assign_default_pid_file: (Hash[Symbol, untyped] attributes, String process_name, String pids_dir) -> String?
|
|
41
|
+
|
|
42
|
+
def validate_process!: (ProcessProxy process) -> void
|
|
43
|
+
|
|
44
|
+
def validate_unique_process!: (ProcessProxy process) -> void
|
|
45
|
+
|
|
46
|
+
def validate_required_attributes!: (ProcessProxy process) -> void
|
|
47
|
+
|
|
48
|
+
def validate_unique_pid_file!: (ProcessProxy process) -> void
|
|
49
|
+
|
|
50
|
+
def validate_stop_signals!: (ProcessProxy process) -> void
|
|
51
|
+
|
|
52
|
+
def validate_stop_signal_order!: (Array[Symbol | Integer] stop_signals) -> void
|
|
53
|
+
|
|
54
|
+
def validate_stop_grace_time!: (Array[Symbol | Integer] stop_signals, Integer? stop_grace_time) -> void
|
|
55
|
+
|
|
56
|
+
def warn_unless_pid_known: (ProcessProxy process, String? default_pid_file) -> void
|
|
57
|
+
|
|
58
|
+
def config_error!: (String message) -> bot
|
|
59
|
+
|
|
60
|
+
# The process names and pid files an application's config has used
|
|
61
|
+
class Registry
|
|
62
|
+
@process_keys: Hash[Array[String?], nil]
|
|
63
|
+
@pid_files: Hash[String, nil]
|
|
64
|
+
|
|
65
|
+
def initialize: () -> void
|
|
66
|
+
|
|
67
|
+
def add_process?: (_ToS? group, _ToS name) -> bool
|
|
68
|
+
|
|
69
|
+
def add_pid_file?: (String pid_file) -> bool
|
|
70
|
+
|
|
71
|
+
private
|
|
72
|
+
|
|
73
|
+
def add?: [K < Hash::_Key] (Hash[K, nil] keys, K key) -> bool
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# Creates the processes of a process's children, for ProcessFactory,
|
|
77
|
+
# which is the only class that includes it
|
|
78
|
+
module Children
|
|
79
|
+
@attributes: Hash[Symbol, untyped]
|
|
80
|
+
@process_block: process_block
|
|
81
|
+
|
|
82
|
+
def create_child_process: (String name, Integer pid, Logger logger) -> Process
|
|
83
|
+
|
|
84
|
+
private
|
|
85
|
+
|
|
86
|
+
def inherited_attributes: () -> Hash[Symbol, untyped]
|
|
87
|
+
|
|
88
|
+
def validate_child_process!: (ProcessProxy child) -> void
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# self in a process block. Any attribute can be set with `name = value`,
|
|
93
|
+
# `name value` or `name!` (for true), and read back with `name`.
|
|
94
|
+
class ProcessProxy
|
|
95
|
+
attr_reader attributes: Hash[Symbol, untyped]
|
|
96
|
+
attr_reader watches: Hash[Symbol, Hash[Symbol, untyped]]
|
|
97
|
+
attr_reader name: String
|
|
98
|
+
|
|
99
|
+
def initialize: (String process_name, Hash[Symbol, untyped] attributes, process_block process_block) -> void
|
|
100
|
+
|
|
101
|
+
# Sets or reads an attribute
|
|
102
|
+
def method_missing: (Symbol name, *untyped args) -> untyped
|
|
103
|
+
|
|
104
|
+
def respond_to_missing?: (Symbol name, bool? include_private) -> bool
|
|
105
|
+
|
|
106
|
+
# Whether a config can set the attribute on a process
|
|
107
|
+
def self.attribute?: (Symbol name) -> bool
|
|
108
|
+
|
|
109
|
+
def self.attribute_names: () -> Array[Symbol]
|
|
110
|
+
|
|
111
|
+
def checks: (Symbol name, ?Hash[Symbol, untyped] options) -> Hash[Symbol, untyped]
|
|
112
|
+
|
|
113
|
+
# The block configures the children like a process block
|
|
114
|
+
def monitor_children: () ?{ (ProcessProxy child) [self: ProcessProxy] -> void } -> process_block?
|
|
115
|
+
|
|
116
|
+
def to_process: () -> Process
|
|
117
|
+
|
|
118
|
+
private
|
|
119
|
+
|
|
120
|
+
def attribute_call: (Symbol name, Array[untyped] args) -> ([Symbol, bool] | [Symbol, bool, untyped])?
|
|
121
|
+
|
|
122
|
+
def unknown_attribute!: (Symbol key) -> bot
|
|
123
|
+
|
|
124
|
+
def suggest: (Symbol key) -> String?
|
|
125
|
+
end
|
|
126
|
+
end
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
module Bluepill
|
|
2
|
+
# Logs to a file or syslog, with nested prefixes
|
|
3
|
+
class Logger
|
|
4
|
+
# Where a Logger without a parent logger writes: a LoggerAdapter, or
|
|
5
|
+
# Syslog
|
|
6
|
+
interface _Backend
|
|
7
|
+
def emerg: (String message) -> void
|
|
8
|
+
|
|
9
|
+
def alert: (String message) -> void
|
|
10
|
+
|
|
11
|
+
def crit: (String message) -> void
|
|
12
|
+
|
|
13
|
+
def err: (String message) -> void
|
|
14
|
+
|
|
15
|
+
def warning: (String message) -> void
|
|
16
|
+
|
|
17
|
+
def notice: (String message) -> void
|
|
18
|
+
|
|
19
|
+
def info: (String message) -> void
|
|
20
|
+
|
|
21
|
+
def debug: (String message) -> void
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
type options = {
|
|
25
|
+
?logger: Logger,
|
|
26
|
+
?prefix: String?,
|
|
27
|
+
?stdout: bool,
|
|
28
|
+
?log_file: String?,
|
|
29
|
+
?identity: String,
|
|
30
|
+
?log_level: (Symbol | String)?
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
LOG_METHODS: Array[Symbol]
|
|
34
|
+
|
|
35
|
+
# A ::Logger that also answers to the syslog method names
|
|
36
|
+
class LoggerAdapter < ::Logger
|
|
37
|
+
LOGGER_EQUIVALENTS: Hash[Symbol, Symbol]
|
|
38
|
+
|
|
39
|
+
alias err error
|
|
40
|
+
|
|
41
|
+
alias warning warn
|
|
42
|
+
|
|
43
|
+
alias emerg fatal
|
|
44
|
+
|
|
45
|
+
alias alert warn
|
|
46
|
+
|
|
47
|
+
alias crit fatal
|
|
48
|
+
|
|
49
|
+
alias notice info
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
@options: options
|
|
53
|
+
@logger: Logger | (Object & _Backend)
|
|
54
|
+
@prefix: String?
|
|
55
|
+
@stdout: bool?
|
|
56
|
+
@level: Integer
|
|
57
|
+
@names: Array[String?]
|
|
58
|
+
@label: String?
|
|
59
|
+
@sink: Array[Object & _Backend]
|
|
60
|
+
@prefixes: Hash[String?, Logger]
|
|
61
|
+
|
|
62
|
+
def initialize: (?options options) -> void
|
|
63
|
+
|
|
64
|
+
def emerg: (_ToS msg, ?Array[String?]? prefix) -> void
|
|
65
|
+
|
|
66
|
+
def alert: (_ToS msg, ?Array[String?]? prefix) -> void
|
|
67
|
+
|
|
68
|
+
def crit: (_ToS msg, ?Array[String?]? prefix) -> void
|
|
69
|
+
|
|
70
|
+
def err: (_ToS msg, ?Array[String?]? prefix) -> void
|
|
71
|
+
|
|
72
|
+
def warning: (_ToS msg, ?Array[String?]? prefix) -> void
|
|
73
|
+
|
|
74
|
+
def notice: (_ToS msg, ?Array[String?]? prefix) -> void
|
|
75
|
+
|
|
76
|
+
def info: (_ToS msg, ?Array[String?]? prefix) -> void
|
|
77
|
+
|
|
78
|
+
def debug: (_ToS msg, ?Array[String?]? prefix) -> void
|
|
79
|
+
|
|
80
|
+
def prefix_with: (String? prefix) -> Logger
|
|
81
|
+
|
|
82
|
+
def reopen: () -> void
|
|
83
|
+
|
|
84
|
+
attr_reader level: Integer
|
|
85
|
+
|
|
86
|
+
attr_reader stdout: bool?
|
|
87
|
+
|
|
88
|
+
attr_reader sink: Array[Object & _Backend]
|
|
89
|
+
|
|
90
|
+
attr_reader names: Array[String?]
|
|
91
|
+
|
|
92
|
+
private
|
|
93
|
+
|
|
94
|
+
def settings_from: (Logger | (Object & _Backend) parent, Integer level) -> [Integer, Array[String?], bool?, Array[Object & _Backend]]
|
|
95
|
+
|
|
96
|
+
def label: (Array[String?] names) -> String?
|
|
97
|
+
|
|
98
|
+
def priority: (Symbol | String level) -> Integer
|
|
99
|
+
|
|
100
|
+
def create_logger: () -> (Object & _Backend)
|
|
101
|
+
|
|
102
|
+
def require_syslog: () -> void
|
|
103
|
+
end
|
|
104
|
+
end
|