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,542 @@
|
|
|
1
|
+
module Bluepill
|
|
2
|
+
# Runs commands for a Process, which is the only class that includes it
|
|
3
|
+
module ProcessCommands : _Host
|
|
4
|
+
# What ProcessCommands, and the modules it includes, use from Process
|
|
5
|
+
interface _Host
|
|
6
|
+
include Hooks::_Host
|
|
7
|
+
|
|
8
|
+
%a{pure} def children: () -> Array[Process]
|
|
9
|
+
%a{pure} def start_command: () -> String?
|
|
10
|
+
%a{pure} def stop_command: () -> String?
|
|
11
|
+
%a{pure} def restart_command: () -> String?
|
|
12
|
+
%a{pure} def stop_signals: () -> Array[Symbol | Integer]?
|
|
13
|
+
%a{pure} def start_grace_time: () -> seconds
|
|
14
|
+
%a{pure} def stop_grace_time: () -> seconds
|
|
15
|
+
%a{pure} def restart_grace_time: () -> seconds
|
|
16
|
+
%a{pure} def on_start_timeout: () -> (String | Symbol)
|
|
17
|
+
%a{pure} def monitor_children: () -> bool
|
|
18
|
+
%a{pure} def uid: () -> String?
|
|
19
|
+
%a{pure} def gid: () -> String?
|
|
20
|
+
%a{pure} def working_dir: () -> String?
|
|
21
|
+
%a{pure} def pid_file: () -> String?
|
|
22
|
+
%a{pure} def stdin: () -> String?
|
|
23
|
+
%a{pure} def stdout: () -> String?
|
|
24
|
+
%a{pure} def stderr: () -> String?
|
|
25
|
+
%a{pure} def supplementary_groups: () -> Array[String]?
|
|
26
|
+
def daemonize?: () -> bool
|
|
27
|
+
def monitor_children?: () -> bool
|
|
28
|
+
def clean_threads: () -> void
|
|
29
|
+
def signal_process: (Integer | String | Symbol code) -> bool
|
|
30
|
+
def unlink_pid: () -> void
|
|
31
|
+
def clear_pid: () -> void
|
|
32
|
+
def skip_ticks_for: (seconds seconds) -> Integer
|
|
33
|
+
def dispatch!: (Symbol | String event, ?String? reason) -> bool
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
include Execution
|
|
37
|
+
include Hooks
|
|
38
|
+
include StopSignals
|
|
39
|
+
|
|
40
|
+
@threads: Array[Thread]
|
|
41
|
+
@stopping_pid: Integer?
|
|
42
|
+
|
|
43
|
+
def start_process: () -> Integer
|
|
44
|
+
|
|
45
|
+
def run_start_command: (String command) -> void
|
|
46
|
+
|
|
47
|
+
def daemonize_process: (String command) -> void
|
|
48
|
+
|
|
49
|
+
def stop_process: () -> Integer
|
|
50
|
+
|
|
51
|
+
def journal_children: () -> void
|
|
52
|
+
|
|
53
|
+
def send_stop: () -> void
|
|
54
|
+
|
|
55
|
+
def run_stop_command: (String command) -> void
|
|
56
|
+
|
|
57
|
+
def restart_process: () -> Integer
|
|
58
|
+
|
|
59
|
+
def run_restart_command: (String command) -> Integer
|
|
60
|
+
|
|
61
|
+
def cleanup_process: () -> void
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Stops a Process with its stop_signals, with their delays
|
|
65
|
+
module ProcessCommands::StopSignals : ProcessCommands::StopSignals::_Host
|
|
66
|
+
# What StopSignals uses from Process
|
|
67
|
+
interface _Host
|
|
68
|
+
%a{pure} def logger: () -> Logger
|
|
69
|
+
%a{pure} def stop_grace_time: () -> seconds
|
|
70
|
+
def actual_pid: () -> Integer?
|
|
71
|
+
def signal_process: (Integer | String | Symbol code) -> bool
|
|
72
|
+
def cleanup_process: () -> void
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
@threads: Array[Thread]
|
|
76
|
+
|
|
77
|
+
def send_stop_signals_in_background: (Array[Symbol | Integer] signals) -> Array[Thread]
|
|
78
|
+
|
|
79
|
+
def send_stop_signals: (Array[Symbol | Integer] signals) -> void
|
|
80
|
+
|
|
81
|
+
def send_later_stop_signals: (Array[Symbol | Integer] signals) -> seconds?
|
|
82
|
+
|
|
83
|
+
def send_stop_signal: (Symbol | Integer signal) -> bool
|
|
84
|
+
|
|
85
|
+
def running_after?: (Integer delay) -> bool
|
|
86
|
+
|
|
87
|
+
def wait_for_stop: (seconds seconds) -> void
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# Runs a Process's commands as its user, in its working_dir, with its
|
|
91
|
+
# environment and standard streams
|
|
92
|
+
module ProcessCommands::Execution : ProcessCommands::Execution::_Host
|
|
93
|
+
# What Execution uses from Process
|
|
94
|
+
interface _Host
|
|
95
|
+
%a{pure} def logger: () -> Logger
|
|
96
|
+
%a{pure} def uid: () -> String?
|
|
97
|
+
%a{pure} def gid: () -> String?
|
|
98
|
+
%a{pure} def working_dir: () -> String?
|
|
99
|
+
%a{pure} def environment: () -> Hash[_ToS, _ToS]?
|
|
100
|
+
%a{pure} def pid_file: () -> String?
|
|
101
|
+
%a{pure} def stdin: () -> String?
|
|
102
|
+
%a{pure} def stdout: () -> String?
|
|
103
|
+
%a{pure} def stderr: () -> String?
|
|
104
|
+
%a{pure} def supplementary_groups: () -> Array[String]?
|
|
105
|
+
def actual_pid: () -> Integer?
|
|
106
|
+
def dispatch!: (Symbol | String event, ?String? reason) -> bool
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def prepare_command: (String command) -> String
|
|
110
|
+
|
|
111
|
+
def substitute_pid: (String command, Integer? pid) -> String
|
|
112
|
+
|
|
113
|
+
def system_command_options: () -> System::command_options
|
|
114
|
+
|
|
115
|
+
# Runs the block, and dispatches next_state if it takes longer than secs
|
|
116
|
+
def with_timeout: [T] (seconds secs, String | Symbol next_state) { (Numeric secs) -> T } -> (T | bool)
|
|
117
|
+
|
|
118
|
+
def run_command: (String cmd, String description, ?System::command_options options) -> void
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# Runs the commands a Process has around its starts and stops, and on each
|
|
122
|
+
# change of state
|
|
123
|
+
module ProcessCommands::Hooks : ProcessCommands::Hooks::_Host
|
|
124
|
+
# What Hooks uses from Process
|
|
125
|
+
interface _Host
|
|
126
|
+
%a{pure} def name: () -> String
|
|
127
|
+
%a{pure} def logger: () -> Logger
|
|
128
|
+
%a{pure} def pre_start_command: () -> String?
|
|
129
|
+
%a{pure} def post_start_command: () -> String?
|
|
130
|
+
%a{pure} def pre_stop_command: () -> String?
|
|
131
|
+
%a{pure} def post_stop_command: () -> String?
|
|
132
|
+
%a{pure} def notify_command: () -> String?
|
|
133
|
+
%a{pure} def hook_timeout: () -> seconds
|
|
134
|
+
%a{pure} def app_name: () -> String?
|
|
135
|
+
%a{pure} def group_name: () -> String?
|
|
136
|
+
%a{pure} def environment: () -> Hash[_ToS, _ToS]?
|
|
137
|
+
def actual_pid: () -> Integer?
|
|
138
|
+
def system_command_options: () -> System::command_options
|
|
139
|
+
def substitute_pid: (String command, Integer? pid) -> String
|
|
140
|
+
def run_command: (String cmd, String description, ?System::command_options options) -> void
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
@stopping_pid: Integer?
|
|
144
|
+
@actual_pid: Integer?
|
|
145
|
+
@last_pid: Integer?
|
|
146
|
+
@transition_reason: String?
|
|
147
|
+
|
|
148
|
+
def pre_start_process: () -> void
|
|
149
|
+
|
|
150
|
+
def pre_stop_process: () -> void
|
|
151
|
+
|
|
152
|
+
def post_stop_process: () -> Thread?
|
|
153
|
+
|
|
154
|
+
def post_start_process: () -> Thread?
|
|
155
|
+
|
|
156
|
+
def notify_transition: (_Transition transition) -> Thread?
|
|
157
|
+
|
|
158
|
+
def notify_environment: (_Transition transition, Integer? pid) -> Hash[String, String]
|
|
159
|
+
|
|
160
|
+
def run_hook_in_background: (String command, String description, Integer? pid, ?Hash[String, String] env) -> Thread
|
|
161
|
+
|
|
162
|
+
def run_hook: (String command, String description, Integer? pid, ?Hash[String, String] env) -> void
|
|
163
|
+
|
|
164
|
+
def hook_options: (Hash[String, String] env) -> System::command_options
|
|
165
|
+
|
|
166
|
+
private
|
|
167
|
+
|
|
168
|
+
attr_reader stopping_pid: Integer?
|
|
169
|
+
|
|
170
|
+
attr_reader transition_reason: String?
|
|
171
|
+
|
|
172
|
+
def cached_pid: () -> Integer?
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
# A monitored process
|
|
176
|
+
class Process
|
|
177
|
+
include ProcessCommands
|
|
178
|
+
include Attributes
|
|
179
|
+
include Pid
|
|
180
|
+
include Children
|
|
181
|
+
include StateMachine
|
|
182
|
+
include TransitionCallbacks
|
|
183
|
+
include UserCommands
|
|
184
|
+
|
|
185
|
+
attr_accessor name: String
|
|
186
|
+
attr_reader watches: Process::Watches
|
|
187
|
+
attr_accessor triggers: Array[Trigger]
|
|
188
|
+
attr_accessor skip_ticks_until: Integer?
|
|
189
|
+
attr_accessor process_running: bool?
|
|
190
|
+
|
|
191
|
+
attr_reader children: Array[Process]
|
|
192
|
+
attr_reader statistics: ProcessStatistics
|
|
193
|
+
attr_reader logger: Logger
|
|
194
|
+
|
|
195
|
+
@event_mutex: Monitor
|
|
196
|
+
@threads: Array[Thread]
|
|
197
|
+
@actual_pid: Integer?
|
|
198
|
+
@transition_reason: String?
|
|
199
|
+
@transitioned: bool
|
|
200
|
+
|
|
201
|
+
attr_accessor app_name: String?
|
|
202
|
+
attr_accessor group_name: String?
|
|
203
|
+
|
|
204
|
+
# A process's move from one state to another
|
|
205
|
+
class Transition
|
|
206
|
+
attr_reader from_name: Symbol
|
|
207
|
+
attr_reader to_name: Symbol
|
|
208
|
+
|
|
209
|
+
def initialize: (Symbol from_name, Symbol to_name) -> void
|
|
210
|
+
|
|
211
|
+
def loopback?: () -> bool
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
# Methods bluepill defines
|
|
215
|
+
|
|
216
|
+
def initialize: (String process_name, Hash[Symbol, Hash[Symbol, untyped]] checks, ?Hash[Symbol, untyped] options) -> void
|
|
217
|
+
|
|
218
|
+
# Runs the state machine's tick event, then the watches and children
|
|
219
|
+
def tick: () -> void
|
|
220
|
+
|
|
221
|
+
def logger=: (Logger logger) -> void
|
|
222
|
+
|
|
223
|
+
def dispatch!: (Symbol | String event, ?String? reason) -> bool
|
|
224
|
+
|
|
225
|
+
def add_checks: (Hash[Symbol, Hash[Symbol, untyped]] checks, Logger logger) -> void
|
|
226
|
+
|
|
227
|
+
def add_trigger: (Symbol name, Hash[Symbol, untyped] options) -> Array[Trigger]
|
|
228
|
+
|
|
229
|
+
# Runs the watches that are due, and dispatches their events
|
|
230
|
+
def run_watches: () -> void
|
|
231
|
+
|
|
232
|
+
def clean_threads: () -> void
|
|
233
|
+
|
|
234
|
+
def daemonize?: () -> bool
|
|
235
|
+
|
|
236
|
+
def skip_ticks_for: (seconds seconds) -> Integer
|
|
237
|
+
|
|
238
|
+
def skipping_ticks?: () -> bool?
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
# The options a config can set for a Process, and their defaults
|
|
242
|
+
module Process::Attributes
|
|
243
|
+
CONFIGURABLE_ATTRIBUTES: Array[Symbol]
|
|
244
|
+
|
|
245
|
+
attr_accessor pre_start_command: String?
|
|
246
|
+
attr_accessor start_command: String?
|
|
247
|
+
attr_accessor stop_command: String?
|
|
248
|
+
attr_accessor restart_command: String?
|
|
249
|
+
attr_accessor stdout: String?
|
|
250
|
+
attr_accessor stderr: String?
|
|
251
|
+
attr_accessor stdin: String?
|
|
252
|
+
attr_accessor daemonize: bool?
|
|
253
|
+
attr_accessor pid_file: String?
|
|
254
|
+
attr_accessor working_dir: String?
|
|
255
|
+
attr_accessor environment: Hash[_ToS, _ToS]?
|
|
256
|
+
attr_accessor start_grace_time: seconds
|
|
257
|
+
attr_accessor stop_grace_time: seconds
|
|
258
|
+
attr_accessor restart_grace_time: seconds
|
|
259
|
+
attr_accessor uid: String?
|
|
260
|
+
attr_accessor gid: String?
|
|
261
|
+
attr_accessor cache_actual_pid: bool
|
|
262
|
+
attr_accessor monitor_children: bool
|
|
263
|
+
attr_accessor child_process_factory: ProcessFactory?
|
|
264
|
+
attr_accessor pid_command: String?
|
|
265
|
+
attr_accessor auto_start: bool?
|
|
266
|
+
attr_accessor supplementary_groups: Array[String]?
|
|
267
|
+
# Signal names alternating with delays in seconds
|
|
268
|
+
attr_accessor stop_signals: Array[Symbol | Integer]?
|
|
269
|
+
attr_accessor on_start_timeout: String | Symbol
|
|
270
|
+
attr_accessor post_start_command: String?
|
|
271
|
+
attr_accessor pre_stop_command: String?
|
|
272
|
+
attr_accessor post_stop_command: String?
|
|
273
|
+
attr_accessor notify_command: String?
|
|
274
|
+
attr_accessor hook_timeout: seconds
|
|
275
|
+
attr_accessor group_start_noblock: bool
|
|
276
|
+
attr_accessor group_restart_noblock: bool
|
|
277
|
+
attr_accessor group_stop_noblock: bool
|
|
278
|
+
attr_accessor group_unmonitor_noblock: bool
|
|
279
|
+
|
|
280
|
+
def configure: (Hash[Symbol, untyped] options) -> void
|
|
281
|
+
|
|
282
|
+
def apply_defaults: () -> void
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
# Finds, signals and forgets a Process's pid
|
|
286
|
+
module Process::Pid : Process::Pid::_Host
|
|
287
|
+
# What Pid uses from Process
|
|
288
|
+
interface _Host
|
|
289
|
+
%a{pure} def name: () -> String
|
|
290
|
+
%a{pure} def logger: () -> Logger
|
|
291
|
+
%a{pure} def pid_file: () -> String?
|
|
292
|
+
%a{pure} def pid_command: () -> String?
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
@process_running: bool?
|
|
296
|
+
@cache_actual_pid: bool
|
|
297
|
+
@actual_pid: Integer?
|
|
298
|
+
@last_pid: Integer?
|
|
299
|
+
|
|
300
|
+
def process_running?: (?bool force) -> bool
|
|
301
|
+
|
|
302
|
+
def signal_process: (Integer | String | Symbol code) -> bool
|
|
303
|
+
|
|
304
|
+
def cache_actual_pid?: () -> bool
|
|
305
|
+
|
|
306
|
+
def actual_pid: () -> Integer?
|
|
307
|
+
|
|
308
|
+
def pid_from_file: () -> Integer?
|
|
309
|
+
|
|
310
|
+
def pid_from_command: () -> Integer?
|
|
311
|
+
|
|
312
|
+
def positive_pid: (Integer pid) -> Integer?
|
|
313
|
+
|
|
314
|
+
def actual_pid=: (Integer pid) -> void
|
|
315
|
+
|
|
316
|
+
def clear_pid: () -> nil
|
|
317
|
+
|
|
318
|
+
def unlink_pid: () -> void
|
|
319
|
+
end
|
|
320
|
+
|
|
321
|
+
# Keeps a Process for each of a Process's children, when it monitors them
|
|
322
|
+
module Process::Children : Process::Children::_Host
|
|
323
|
+
# What Children uses from Process
|
|
324
|
+
interface _Host
|
|
325
|
+
%a{pure} def name: () -> String
|
|
326
|
+
%a{pure} def logger: () -> Logger
|
|
327
|
+
%a{pure} def monitor_children: () -> bool
|
|
328
|
+
%a{pure} def child_process_factory: () -> ProcessFactory?
|
|
329
|
+
def daemonize?: () -> bool
|
|
330
|
+
def actual_pid: () -> Integer?
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
@children: Array[Process]
|
|
334
|
+
|
|
335
|
+
def monitor_children?: () -> bool
|
|
336
|
+
|
|
337
|
+
def refresh_children!: () -> void
|
|
338
|
+
|
|
339
|
+
def add_children: (Array[Integer] child_pids) -> void
|
|
340
|
+
|
|
341
|
+
def new_child: (ProcessFactory factory, Integer child_pid) -> Process
|
|
342
|
+
end
|
|
343
|
+
|
|
344
|
+
# Moves a Process between its states
|
|
345
|
+
module Process::StateMachine : Process::StateMachine::_Host
|
|
346
|
+
# What StateMachine uses from Process
|
|
347
|
+
interface _Host
|
|
348
|
+
%a{pure} def auto_start: () -> bool?
|
|
349
|
+
def process_running?: (?bool force) -> bool
|
|
350
|
+
def before_transition: (Process::Transition transition) -> true
|
|
351
|
+
def after_transition: (Process::Transition transition) -> void
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
TICKS: Hash[Symbol, Array[Symbol]]
|
|
355
|
+
|
|
356
|
+
TRANSITIONS: Hash[Symbol, Hash[Symbol, Symbol]]
|
|
357
|
+
|
|
358
|
+
STATES: Array[Symbol]
|
|
359
|
+
|
|
360
|
+
LOOPBACKS: Hash[Symbol, Process::Transition]
|
|
361
|
+
|
|
362
|
+
attr_accessor state: Symbol
|
|
363
|
+
|
|
364
|
+
def unmonitored?: () -> bool
|
|
365
|
+
|
|
366
|
+
def up?: () -> bool
|
|
367
|
+
|
|
368
|
+
def down?: () -> bool
|
|
369
|
+
|
|
370
|
+
def starting?: () -> bool
|
|
371
|
+
|
|
372
|
+
def stopping?: () -> bool
|
|
373
|
+
|
|
374
|
+
def restarting?: () -> bool
|
|
375
|
+
|
|
376
|
+
def start: () -> bool
|
|
377
|
+
|
|
378
|
+
def stop: () -> bool
|
|
379
|
+
|
|
380
|
+
def unmonitor: () -> bool
|
|
381
|
+
|
|
382
|
+
def restart: () -> bool
|
|
383
|
+
|
|
384
|
+
# Moves the process to the state an event leads to, and returns whether
|
|
385
|
+
# it moved
|
|
386
|
+
def fire_event: (Symbol event) -> bool
|
|
387
|
+
|
|
388
|
+
def tick_target: (Symbol from) -> Symbol?
|
|
389
|
+
|
|
390
|
+
def determine_initial_state: () -> void
|
|
391
|
+
end
|
|
392
|
+
|
|
393
|
+
# Runs what a Process does on its way from one state to another
|
|
394
|
+
module Process::TransitionCallbacks : Process::TransitionCallbacks::_Host
|
|
395
|
+
# What TransitionCallbacks uses from Process
|
|
396
|
+
interface _Host
|
|
397
|
+
%a{pure} def logger: () -> Logger
|
|
398
|
+
%a{pure} def watches: () -> Process::Watches
|
|
399
|
+
%a{pure} def triggers: () -> Array[Trigger]
|
|
400
|
+
%a{pure} def children: () -> Array[Process]
|
|
401
|
+
def monitor_children?: () -> bool
|
|
402
|
+
def clean_threads: () -> void
|
|
403
|
+
def start_process: () -> Integer
|
|
404
|
+
def stop_process: () -> Integer
|
|
405
|
+
def restart_process: () -> Integer
|
|
406
|
+
def post_start_process: () -> Thread?
|
|
407
|
+
def notify_transition: (_Transition transition) -> Thread?
|
|
408
|
+
end
|
|
409
|
+
|
|
410
|
+
STARTS: Array[Symbol]
|
|
411
|
+
|
|
412
|
+
@transitioned: bool
|
|
413
|
+
|
|
414
|
+
def before_transition: (Process::Transition transition) -> true
|
|
415
|
+
|
|
416
|
+
def after_transition: (Process::Transition transition) -> void
|
|
417
|
+
|
|
418
|
+
def notify_triggers: (_Transition transition) -> void
|
|
419
|
+
|
|
420
|
+
def record_transition: (_Transition transition) -> void
|
|
421
|
+
end
|
|
422
|
+
|
|
423
|
+
# The checks that run on a Process every interval, and the events they
|
|
424
|
+
# ask it for
|
|
425
|
+
class Process::Watches
|
|
426
|
+
include Enumerable[ConditionWatch]
|
|
427
|
+
|
|
428
|
+
NO_EVENTS: Array[[Symbol, String]]
|
|
429
|
+
|
|
430
|
+
attr_reader logger: Logger
|
|
431
|
+
|
|
432
|
+
@watches: Array[ConditionWatch]
|
|
433
|
+
|
|
434
|
+
def initialize: () -> void
|
|
435
|
+
|
|
436
|
+
def add: (Symbol name, Hash[Symbol, untyped] options) -> Process::Watches
|
|
437
|
+
|
|
438
|
+
def <<: (ConditionWatch watch) -> Process::Watches
|
|
439
|
+
|
|
440
|
+
def each: () { (ConditionWatch watch) -> void } -> Array[ConditionWatch]
|
|
441
|
+
|
|
442
|
+
def logger=: (Logger logger) -> void
|
|
443
|
+
|
|
444
|
+
def clear_history!: () -> void
|
|
445
|
+
|
|
446
|
+
# Yields for the process's pid on each due watch's thread
|
|
447
|
+
def run: (Integer now) { () -> Integer? } -> Array[[Symbol, String]]
|
|
448
|
+
|
|
449
|
+
private
|
|
450
|
+
|
|
451
|
+
def events: (Array[[ConditionWatch, Thread]] threads) -> Array[[Symbol, String]]
|
|
452
|
+
end
|
|
453
|
+
|
|
454
|
+
# Carries out the commands a user gives a Process from the command line
|
|
455
|
+
module Process::UserCommands : Process::UserCommands::_Host
|
|
456
|
+
# What UserCommands uses from Process
|
|
457
|
+
interface _Host
|
|
458
|
+
%a{pure} def logger: () -> Logger
|
|
459
|
+
%a{pure} def triggers: () -> Array[Trigger]
|
|
460
|
+
def process_running?: (?bool force) -> bool
|
|
461
|
+
def dispatch!: (Symbol | String event, ?String? reason) -> bool
|
|
462
|
+
def stop_process: () -> Integer
|
|
463
|
+
def restart_process: () -> Integer
|
|
464
|
+
end
|
|
465
|
+
|
|
466
|
+
def handle_user_command: (Symbol cmd) -> void
|
|
467
|
+
|
|
468
|
+
def user_start: () -> void
|
|
469
|
+
|
|
470
|
+
def user_stop: () -> void
|
|
471
|
+
|
|
472
|
+
def user_restart: () -> void
|
|
473
|
+
|
|
474
|
+
def user_unmonitor: () -> void
|
|
475
|
+
end
|
|
476
|
+
|
|
477
|
+
# Keeps a short history of a process's events
|
|
478
|
+
class ProcessStatistics
|
|
479
|
+
type event = [Symbol | String, String?, Time]
|
|
480
|
+
|
|
481
|
+
STRFTIME: String
|
|
482
|
+
EVENTS_TO_PERSIST: Integer
|
|
483
|
+
|
|
484
|
+
attr_reader events: Util::RotationalArray[event]
|
|
485
|
+
|
|
486
|
+
def initialize: () -> void
|
|
487
|
+
|
|
488
|
+
def record_event: (Symbol | String event, String? reason) -> Util::RotationalArray[event]
|
|
489
|
+
|
|
490
|
+
def to_s: () -> String
|
|
491
|
+
end
|
|
492
|
+
|
|
493
|
+
# Processes that share a group name. Processes without one are in the
|
|
494
|
+
# group named nil.
|
|
495
|
+
class Group
|
|
496
|
+
attr_accessor name: String?
|
|
497
|
+
attr_accessor processes: Array[Process]
|
|
498
|
+
attr_accessor logger: Logger
|
|
499
|
+
# Not used by bluepill
|
|
500
|
+
attr_accessor process_logger: untyped
|
|
501
|
+
|
|
502
|
+
NOBLOCK: Hash[Symbol, Symbol]
|
|
503
|
+
|
|
504
|
+
def initialize: (String? name, ?{ ?logger: Logger } options) -> void
|
|
505
|
+
|
|
506
|
+
def add_process: (Process process) -> Array[Process]
|
|
507
|
+
|
|
508
|
+
def tick: () -> void
|
|
509
|
+
|
|
510
|
+
def determine_initial_state: () -> void
|
|
511
|
+
|
|
512
|
+
# Proxied events, which return the affected processes as group:process
|
|
513
|
+
|
|
514
|
+
def start: (?String? process_name) -> Array[String]
|
|
515
|
+
|
|
516
|
+
def unmonitor: (?String? process_name) -> Array[String]
|
|
517
|
+
|
|
518
|
+
def stop: (?String? process_name) -> Array[String]
|
|
519
|
+
|
|
520
|
+
def restart: (?String? process_name) -> Array[String]
|
|
521
|
+
|
|
522
|
+
def status: (?String? process_name) -> Array[String]
|
|
523
|
+
|
|
524
|
+
private
|
|
525
|
+
|
|
526
|
+
def send_user_command: (Symbol event, String? process_name) -> Array[String]
|
|
527
|
+
|
|
528
|
+
def targets: (String? process_name) -> Array[Process]
|
|
529
|
+
|
|
530
|
+
def start_user_command: (Process process, Symbol event, bool noblock) -> Thread
|
|
531
|
+
|
|
532
|
+
def noblock?: (Process process, Symbol event) -> bool
|
|
533
|
+
|
|
534
|
+
def status_line: (Process process, ?String? prefix) -> String
|
|
535
|
+
|
|
536
|
+
def add_group_status: (Array[String] lines) -> void
|
|
537
|
+
|
|
538
|
+
def add_children_status: (Array[Process] children, String? prefix, Array[String] lines) -> void
|
|
539
|
+
|
|
540
|
+
def add_process_status: (String process_name, Array[String] lines) -> void
|
|
541
|
+
end
|
|
542
|
+
end
|