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.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +111 -2
  3. data/README.md +16 -13
  4. data/bin/bluepill +21 -8
  5. data/bluepill.gemspec +7 -2
  6. data/lib/bluepill/application/lifecycle.rb +48 -35
  7. data/lib/bluepill/application/listener.rb +2 -4
  8. data/lib/bluepill/application/previous_daemon.rb +12 -14
  9. data/lib/bluepill/application.rb +36 -30
  10. data/lib/bluepill/base_directory.rb +18 -20
  11. data/lib/bluepill/check_registry.rb +104 -0
  12. data/lib/bluepill/clock.rb +1 -3
  13. data/lib/bluepill/condition_watch.rb +46 -54
  14. data/lib/bluepill/controller/directory.rb +1 -3
  15. data/lib/bluepill/controller.rb +35 -37
  16. data/lib/bluepill/daemonize.rb +52 -0
  17. data/lib/bluepill/dsl/app_proxy.rb +68 -64
  18. data/lib/bluepill/dsl/attributes.rb +135 -0
  19. data/lib/bluepill/dsl/process_factory/child_factory.rb +83 -0
  20. data/lib/bluepill/dsl/process_factory/registry.rb +4 -26
  21. data/lib/bluepill/dsl/process_factory.rb +85 -84
  22. data/lib/bluepill/dsl/process_proxy.rb +80 -160
  23. data/lib/bluepill/dsl.rb +16 -15
  24. data/lib/bluepill/errors.rb +190 -0
  25. data/lib/bluepill/group.rb +14 -37
  26. data/lib/bluepill/logger.rb +65 -99
  27. data/lib/bluepill/process/attributes.rb +66 -32
  28. data/lib/bluepill/process/children.rb +6 -7
  29. data/lib/bluepill/process/pid.rb +43 -35
  30. data/lib/bluepill/process/state_machine.rb +15 -59
  31. data/lib/bluepill/process/stop_signals.rb +123 -0
  32. data/lib/bluepill/process/transition.rb +1 -3
  33. data/lib/bluepill/process/transition_callbacks.rb +2 -16
  34. data/lib/bluepill/process/triggers.rb +90 -0
  35. data/lib/bluepill/process/user_commands.rb +1 -1
  36. data/lib/bluepill/process/watches.rb +9 -23
  37. data/lib/bluepill/process.rb +55 -52
  38. data/lib/bluepill/process_commands/execution.rb +16 -24
  39. data/lib/bluepill/process_commands/hooks.rb +1 -31
  40. data/lib/bluepill/process_commands/stop_signals.rb +12 -17
  41. data/lib/bluepill/process_commands.rb +10 -8
  42. data/lib/bluepill/process_conditions/always_true.rb +2 -6
  43. data/lib/bluepill/process_conditions/below_threshold.rb +6 -8
  44. data/lib/bluepill/process_conditions/cpu_usage.rb +1 -4
  45. data/lib/bluepill/process_conditions/file_time.rb +8 -9
  46. data/lib/bluepill/process_conditions/http.rb +29 -67
  47. data/lib/bluepill/process_conditions/mem_usage.rb +7 -45
  48. data/lib/bluepill/process_conditions/process_condition.rb +29 -47
  49. data/lib/bluepill/process_conditions/zombie_process.rb +2 -6
  50. data/lib/bluepill/process_conditions.rb +5 -14
  51. data/lib/bluepill/process_journal/cleanup.rb +5 -53
  52. data/lib/bluepill/process_journal/config.rb +73 -0
  53. data/lib/bluepill/process_journal/entries.rb +128 -0
  54. data/lib/bluepill/process_journal/journal.rb +69 -0
  55. data/lib/bluepill/process_journal/kind.rb +60 -0
  56. data/lib/bluepill/process_journal/lock.rb +9 -4
  57. data/lib/bluepill/process_journal.rb +13 -324
  58. data/lib/bluepill/process_statistics.rb +3 -7
  59. data/lib/bluepill/socket.rb +19 -17
  60. data/lib/bluepill/system/command_options.rb +136 -0
  61. data/lib/bluepill/system/command_result.rb +73 -0
  62. data/lib/bluepill/system/command_setup.rb +3 -4
  63. data/lib/bluepill/system/command_spawn.rb +244 -0
  64. data/lib/bluepill/system/commands.rb +27 -40
  65. data/lib/bluepill/system/daemon.rb +97 -15
  66. data/lib/bluepill/system/files.rb +35 -0
  67. data/lib/bluepill/system/ps.rb +20 -17
  68. data/lib/bluepill/system/ps_table.rb +7 -9
  69. data/lib/bluepill/system/usage.rb +175 -0
  70. data/lib/bluepill/system.rb +7 -192
  71. data/lib/bluepill/trigger.rb +18 -69
  72. data/lib/bluepill/triggers/flapping.rb +12 -8
  73. data/lib/bluepill/units.rb +7 -21
  74. data/lib/bluepill/version.rb +16 -26
  75. data/lib/bluepill.rb +1 -1
  76. data/sig/bluepill/application.rbs +11 -12
  77. data/sig/bluepill/attributes.rbs +48 -0
  78. data/sig/bluepill/checks.rbs +40 -40
  79. data/sig/bluepill/dsl.rbs +100 -59
  80. data/sig/bluepill/errors.rbs +48 -0
  81. data/sig/bluepill/logger.rbs +15 -31
  82. data/sig/bluepill/process.rbs +39 -305
  83. data/sig/bluepill/process_commands.rbs +235 -0
  84. data/sig/bluepill/stop_signals.rbs +21 -0
  85. data/sig/bluepill/system.rbs +191 -101
  86. data/sig/bluepill/version.rbs +17 -0
  87. data/sig/bluepill.rbs +2 -17
  88. data/sig/manifest.yaml +1 -0
  89. metadata +22 -8
  90. data/lib/bluepill/deprecation/custom_checks.rb +0 -193
  91. data/lib/bluepill/deprecation/dsl.rb +0 -141
  92. data/lib/bluepill/deprecation/options.rb +0 -140
  93. data/lib/bluepill/deprecation.rb +0 -92
  94. data/lib/bluepill/dsl/process_factory/children.rb +0 -99
  95. data/sig/bluepill/deprecation.rbs +0 -87
@@ -1,179 +1,10 @@
1
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
2
  # A monitored process
176
3
  class Process
4
+ # The checks a process is made with: each check's name and options, as
5
+ # a Hash or as a list of pairs, which can name a check twice
6
+ type checks = _Each[[Symbol, Hash[Symbol, untyped]]]
7
+
177
8
  include ProcessCommands
178
9
  include Attributes
179
10
  include Pid
@@ -184,7 +15,7 @@ module Bluepill
184
15
 
185
16
  attr_accessor name: String
186
17
  attr_reader watches: Process::Watches
187
- attr_accessor triggers: Array[Trigger]
18
+ attr_reader triggers: Process::Triggers
188
19
  attr_accessor skip_ticks_until: Integer?
189
20
  attr_accessor process_running: bool?
190
21
 
@@ -213,20 +44,18 @@ module Bluepill
213
44
 
214
45
  # Methods bluepill defines
215
46
 
216
- def initialize: (String process_name, Hash[Symbol, Hash[Symbol, untyped]] checks, ?Hash[Symbol, untyped] options) -> void
47
+ def initialize: (String process_name, checks checks, ?logger: untyped, ?actual_pid: Integer?, **untyped attributes) -> void
217
48
 
218
49
  # Runs the state machine's tick event, then the watches and children
219
50
  def tick: () -> void
220
51
 
221
52
  def tick_children: () -> void
222
53
 
223
- def logger=: (Logger logger) -> void
224
-
225
- def dispatch!: (Symbol | String event, ?String? reason) -> bool
54
+ def dispatch!: (Symbol event, ?String? reason) -> bool
226
55
 
227
- def add_checks: (Hash[Symbol, Hash[Symbol, untyped]] checks, Logger logger) -> void
56
+ def add_checks: (checks checks, Logger logger) -> void
228
57
 
229
- def add_trigger: (Symbol name, Hash[Symbol, untyped] options) -> Array[Trigger]
58
+ def add_check: (Symbol name, Hash[Symbol, untyped] options) -> void
230
59
 
231
60
  # Runs the watches that are due, and dispatches their events
232
61
  def run_watches: () -> void
@@ -240,109 +69,6 @@ module Bluepill
240
69
  def skipping_ticks?: () -> bool?
241
70
  end
242
71
 
243
- # The options a config can set for a Process, and their defaults
244
- module Process::Attributes
245
- CONFIGURABLE_ATTRIBUTES: Array[Symbol]
246
-
247
- attr_accessor pre_start_command: String?
248
- attr_accessor start_command: String?
249
- attr_accessor stop_command: String?
250
- attr_accessor restart_command: String?
251
- attr_accessor stdout: String?
252
- attr_accessor stderr: String?
253
- attr_accessor stdin: String?
254
- attr_accessor daemonize: bool?
255
- attr_accessor pid_file: String?
256
- attr_accessor working_dir: String?
257
- attr_accessor environment: Hash[_ToS, _ToS]?
258
- attr_accessor start_grace_time: seconds
259
- attr_accessor stop_grace_time: seconds
260
- attr_accessor restart_grace_time: seconds
261
- attr_accessor uid: String?
262
- attr_accessor gid: String?
263
- attr_accessor cache_actual_pid: bool
264
- attr_accessor monitor_children: bool
265
- attr_accessor child_process_factory: ProcessFactory?
266
- attr_accessor pid_command: String?
267
- attr_accessor auto_start: bool?
268
- attr_accessor supplementary_groups: Array[String]?
269
- # Signal names alternating with delays in seconds
270
- attr_accessor stop_signals: Array[Symbol | Integer]?
271
- attr_accessor on_start_timeout: String | Symbol
272
- attr_accessor post_start_command: String?
273
- attr_accessor pre_stop_command: String?
274
- attr_accessor post_stop_command: String?
275
- attr_accessor notify_command: String?
276
- attr_accessor hook_timeout: seconds
277
- attr_accessor group_start_noblock: bool
278
- attr_accessor group_restart_noblock: bool
279
- attr_accessor group_stop_noblock: bool
280
- attr_accessor group_unmonitor_noblock: bool
281
-
282
- def configure: (Hash[Symbol, untyped] options) -> void
283
-
284
- def apply_defaults: () -> void
285
- end
286
-
287
- # Finds, signals and forgets a Process's pid
288
- module Process::Pid : Process::Pid::_Host
289
- # What Pid uses from Process
290
- interface _Host
291
- %a{pure} def name: () -> String
292
- %a{pure} def logger: () -> Logger
293
- %a{pure} def pid_file: () -> String?
294
- %a{pure} def pid_command: () -> String?
295
- end
296
-
297
- @process_running: bool?
298
- @cache_actual_pid: bool
299
- @actual_pid: Integer?
300
- @last_pid: Integer?
301
-
302
- def process_running?: (?bool force) -> bool
303
-
304
- def signal_process: (Integer | String | Symbol code) -> bool
305
-
306
- def cache_actual_pid?: () -> bool
307
-
308
- def actual_pid: () -> Integer?
309
-
310
- def pid_from_file: () -> Integer?
311
-
312
- def pid_from_command: () -> Integer?
313
-
314
- def positive_pid: (Integer pid) -> Integer?
315
-
316
- def actual_pid=: (Integer pid) -> void
317
-
318
- def clear_pid: () -> nil
319
-
320
- def unlink_pid: () -> void
321
- end
322
-
323
- # Keeps a Process for each of a Process's children, when it monitors them
324
- module Process::Children : Process::Children::_Host
325
- # What Children uses from Process
326
- interface _Host
327
- %a{pure} def name: () -> String
328
- %a{pure} def logger: () -> Logger
329
- %a{pure} def monitor_children: () -> bool
330
- %a{pure} def child_process_factory: () -> ProcessFactory?
331
- def daemonize?: () -> bool
332
- def actual_pid: () -> Integer?
333
- end
334
-
335
- @children: Array[Process]
336
-
337
- def monitor_children?: () -> bool
338
-
339
- def refresh_children!: () -> void
340
-
341
- def add_children: (Array[Integer] child_pids) -> void
342
-
343
- def new_child: (ProcessFactory factory, Integer child_pid) -> Process
344
- end
345
-
346
72
  # Moves a Process between its states
347
73
  module Process::StateMachine : Process::StateMachine::_Host
348
74
  # What StateMachine uses from Process
@@ -375,14 +101,6 @@ module Bluepill
375
101
 
376
102
  def restarting?: () -> bool
377
103
 
378
- def start: () -> bool
379
-
380
- def stop: () -> bool
381
-
382
- def unmonitor: () -> bool
383
-
384
- def restart: () -> bool
385
-
386
104
  # Moves the process to the state an event leads to, and returns whether
387
105
  # it moved
388
106
  def fire_event: (Symbol event) -> bool
@@ -398,7 +116,7 @@ module Bluepill
398
116
  interface _Host
399
117
  %a{pure} def logger: () -> Logger
400
118
  %a{pure} def watches: () -> Process::Watches
401
- %a{pure} def triggers: () -> Array[Trigger]
119
+ %a{pure} def triggers: () -> Process::Triggers
402
120
  %a{pure} def children: () -> Array[Process]
403
121
  def monitor_children?: () -> bool
404
122
  def clean_threads: () -> void
@@ -412,13 +130,12 @@ module Bluepill
412
130
  STARTS: Array[Symbol]
413
131
 
414
132
  @transitioned: bool
133
+ @triggers: Process::Triggers
415
134
 
416
135
  def before_transition: (Process::Transition transition) -> true
417
136
 
418
137
  def after_transition: (Process::Transition transition) -> void
419
138
 
420
- def notify_triggers: (_Transition transition) -> void
421
-
422
139
  def record_transition: (_Transition transition) -> void
423
140
  end
424
141
 
@@ -433,16 +150,14 @@ module Bluepill
433
150
 
434
151
  @watches: Array[ConditionWatch]
435
152
 
436
- def initialize: () -> void
153
+ def initialize: (logger: Logger) -> void
437
154
 
438
- def add: (Symbol name, Hash[Symbol, untyped] options) -> Process::Watches
155
+ def add: (Symbol name, **untyped options) -> Process::Watches
439
156
 
440
157
  def <<: (ConditionWatch watch) -> Process::Watches
441
158
 
442
159
  def each: () { (ConditionWatch watch) -> void } -> Array[ConditionWatch]
443
160
 
444
- def logger=: (Logger logger) -> void
445
-
446
161
  def clear_history!: () -> void
447
162
 
448
163
  # Yields for the process's pid on each due watch's thread
@@ -453,14 +168,35 @@ module Bluepill
453
168
  def events: (Array[[ConditionWatch, Thread]] threads) -> Array[[Symbol, String]]
454
169
  end
455
170
 
171
+ # The triggers a Process tells of its transitions
172
+ class Process::Triggers
173
+ include Enumerable[Trigger]
174
+
175
+ attr_reader logger: Logger
176
+
177
+ @triggers: Array[Trigger]
178
+
179
+ def initialize: (logger: Logger) -> void
180
+
181
+ def add: (Class klass, Process process, **untyped options) -> Process::Triggers
182
+
183
+ def <<: (Trigger trigger) -> Process::Triggers
184
+
185
+ def each: () { (Trigger trigger) -> void } -> Array[Trigger]
186
+
187
+ def notify: (_Transition transition) -> Array[Trigger]
188
+
189
+ def reset!: () -> Array[Trigger]
190
+ end
191
+
456
192
  # Carries out the commands a user gives a Process from the command line
457
193
  module Process::UserCommands : Process::UserCommands::_Host
458
194
  # What UserCommands uses from Process
459
195
  interface _Host
460
196
  %a{pure} def logger: () -> Logger
461
- %a{pure} def triggers: () -> Array[Trigger]
197
+ %a{pure} def triggers: () -> Process::Triggers
462
198
  def process_running?: (?bool force) -> bool
463
- def dispatch!: (Symbol | String event, ?String? reason) -> bool
199
+ def dispatch!: (Symbol event, ?String? reason) -> bool
464
200
  def stop_process: () -> Integer
465
201
  def restart_process: () -> Integer
466
202
  end
@@ -478,7 +214,7 @@ module Bluepill
478
214
 
479
215
  # Keeps a short history of a process's events
480
216
  class ProcessStatistics
481
- type event = [Symbol | String, String?, Time]
217
+ type event = [Symbol, String?, Time]
482
218
 
483
219
  STRFTIME: String
484
220
  EVENTS_TO_PERSIST: Integer
@@ -487,7 +223,7 @@ module Bluepill
487
223
 
488
224
  def initialize: () -> void
489
225
 
490
- def record_event: (Symbol | String event, String? reason) -> Util::RotationalArray[event]
226
+ def record_event: (Symbol event, String? reason) -> Util::RotationalArray[event]
491
227
 
492
228
  def to_s: () -> String
493
229
  end
@@ -498,12 +234,10 @@ module Bluepill
498
234
  attr_accessor name: String?
499
235
  attr_accessor processes: Array[Process]
500
236
  attr_accessor logger: Logger
501
- # Not used by bluepill
502
- attr_accessor process_logger: untyped
503
237
 
504
238
  NOBLOCK: Hash[Symbol, Symbol]
505
239
 
506
- def initialize: (String? name, ?{ ?logger: Logger } options) -> void
240
+ def initialize: (String? name, ?logger: untyped) -> void
507
241
 
508
242
  def add_process: (Process process) -> Array[Process]
509
243
 
@@ -0,0 +1,235 @@
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: () -> Process::StopSignals?
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: () -> 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 environment: () -> Hash[_ToS, _ToS]?
22
+ %a{pure} def pid_file: () -> String?
23
+ %a{pure} def stdin: () -> String?
24
+ %a{pure} def stdout: () -> String?
25
+ %a{pure} def stderr: () -> String?
26
+ %a{pure} def supplementary_groups: () -> Array[String]?
27
+ def daemonize?: () -> bool
28
+ def monitor_children?: () -> bool
29
+ def clean_threads: () -> void
30
+ def signal_process: (Integer | String | Symbol code) -> bool
31
+ def unlink_pid: () -> void
32
+ def clear_pid: () -> void
33
+ def skip_ticks_for: (seconds seconds) -> Integer
34
+ def journal: () -> ProcessJournal::Journal
35
+ def dispatch!: (Symbol event, ?String? reason) -> bool
36
+ end
37
+
38
+ include Execution
39
+ include Hooks
40
+ include StopSignals
41
+
42
+ @threads: Array[Thread]
43
+ @stopping_pid: Integer?
44
+
45
+ def start_process: () -> Integer
46
+
47
+ def run_start_command: (String command) -> void
48
+
49
+ def daemonize_process: (String command) -> void
50
+
51
+ def stop_process: () -> Integer
52
+
53
+ def journal_children: () -> void
54
+
55
+ def send_stop: () -> void
56
+
57
+ def run_stop_command: (String command) -> void
58
+
59
+ def restart_process: () -> Integer
60
+
61
+ def run_restart_command: (String command) -> Integer
62
+
63
+ def cleanup_process: () -> void
64
+ end
65
+
66
+ # Stops a Process with its stop_signals, with their delays
67
+ module ProcessCommands::StopSignals : ProcessCommands::StopSignals::_Host
68
+ # What StopSignals uses from Process
69
+ interface _Host
70
+ %a{pure} def logger: () -> Logger
71
+ %a{pure} def stop_grace_time: () -> seconds
72
+ def actual_pid: () -> Integer?
73
+ def signal_process: (Integer | String | Symbol code) -> bool
74
+ def cleanup_process: () -> void
75
+ end
76
+
77
+ @threads: Array[Thread]
78
+
79
+ def send_stop_signals_in_background: (Process::StopSignals signals) -> Array[Thread]
80
+
81
+ def send_stop_signals: (Process::StopSignals signals) -> void
82
+
83
+ def send_later_stop_signals: (Process::StopSignals signals) -> seconds?
84
+
85
+ def send_stop_signal: (Symbol signal) -> bool
86
+
87
+ def running_after?: (Integer delay) -> bool
88
+
89
+ def wait_for_stop: (seconds seconds) -> void
90
+ end
91
+
92
+ # Runs a Process's commands as its user, in its working_dir, with its
93
+ # environment and standard streams
94
+ module ProcessCommands::Execution : ProcessCommands::Execution::_Host
95
+ # What Execution uses from Process
96
+ interface _Host
97
+ %a{pure} def logger: () -> Logger
98
+ %a{pure} def uid: () -> String?
99
+ %a{pure} def gid: () -> String?
100
+ %a{pure} def working_dir: () -> String?
101
+ %a{pure} def environment: () -> Hash[_ToS, _ToS]?
102
+ %a{pure} def stdin: () -> String?
103
+ %a{pure} def stdout: () -> String?
104
+ %a{pure} def stderr: () -> String?
105
+ %a{pure} def supplementary_groups: () -> Array[String]?
106
+ def actual_pid: () -> Integer?
107
+ def dispatch!: (Symbol event, ?String? reason) -> bool
108
+ end
109
+
110
+ def prepare_command: (String command) -> String
111
+
112
+ def substitute_pid: (String command, Integer? pid) -> String
113
+
114
+ def command_options: () -> System::CommandOptions
115
+
116
+ # Runs the block, and dispatches next_state if it takes longer than secs
117
+ def with_timeout: [T] (seconds secs, Symbol next_state) { (Numeric secs) -> T } -> (T | bool)
118
+
119
+ def run_command: (String cmd, String description, ?System::CommandOptions options) -> void
120
+ end
121
+
122
+ # Runs the commands a Process has around its starts and stops, and on each
123
+ # change of state
124
+ module ProcessCommands::Hooks : ProcessCommands::Hooks::_Host
125
+ # What Hooks uses from Process
126
+ interface _Host
127
+ %a{pure} def name: () -> String
128
+ %a{pure} def logger: () -> Logger
129
+ %a{pure} def pre_start_command: () -> String?
130
+ %a{pure} def post_start_command: () -> String?
131
+ %a{pure} def pre_stop_command: () -> String?
132
+ %a{pure} def post_stop_command: () -> String?
133
+ %a{pure} def notify_command: () -> String?
134
+ %a{pure} def hook_timeout: () -> seconds
135
+ %a{pure} def app_name: () -> String?
136
+ %a{pure} def group_name: () -> String?
137
+ def actual_pid: () -> Integer?
138
+ def cached_pid: () -> Integer?
139
+ def command_options: () -> System::CommandOptions
140
+ def substitute_pid: (String command, Integer? pid) -> String
141
+ def run_command: (String cmd, String description, ?System::CommandOptions options) -> void
142
+ end
143
+
144
+ @stopping_pid: Integer?
145
+ @transition_reason: String?
146
+
147
+ def pre_start_process: () -> void
148
+
149
+ def pre_stop_process: () -> void
150
+
151
+ def post_stop_process: () -> Thread?
152
+
153
+ def post_start_process: () -> Thread?
154
+
155
+ def notify_transition: (_Transition transition) -> Thread?
156
+
157
+ def notify_environment: (_Transition transition, Integer? pid) -> Hash[String, String]
158
+
159
+ def run_hook_in_background: (String command, String description, Integer? pid, ?Hash[String, String] env) -> Thread
160
+
161
+ def run_hook: (String command, String description, Integer? pid, ?Hash[String, String] env) -> void
162
+
163
+ private
164
+
165
+ attr_reader stopping_pid: Integer?
166
+
167
+ attr_reader transition_reason: String?
168
+ end
169
+
170
+ # Finds, signals and forgets a Process's pid
171
+ module Process::Pid : Process::Pid::_Host
172
+ # What Pid uses from Process
173
+ interface _Host
174
+ %a{pure} def name: () -> String
175
+ %a{pure} def logger: () -> Logger
176
+ %a{pure} def pid_file: () -> String?
177
+ %a{pure} def pid_command: () -> String?
178
+ end
179
+
180
+ @process_running: bool?
181
+ @cache_actual_pid: bool
182
+ @actual_pid: Integer?
183
+ @last_pid: Integer?
184
+ @journal: ProcessJournal::Journal?
185
+
186
+ def process_running?: (?bool force) -> bool
187
+
188
+ def signal_process: (Integer | String | Symbol code) -> bool
189
+
190
+ def cache_actual_pid?: () -> bool
191
+
192
+ def actual_pid: () -> Integer?
193
+
194
+ def pid_from_file: () -> Integer?
195
+
196
+ def pid_from_command: () -> Integer?
197
+
198
+ def warn_if_missing: (String file) -> nil
199
+
200
+ def actual_pid=: (Integer pid) -> void
201
+
202
+ # The pid, or the last one it had if it has died
203
+ def cached_pid: () -> Integer?
204
+
205
+ def journal: () -> ProcessJournal::Journal
206
+
207
+ def clear_pid: () -> nil
208
+
209
+ def unlink_pid: () -> void
210
+ end
211
+
212
+ # Keeps a Process for each of a Process's children, when it monitors them
213
+ module Process::Children : Process::Children::_Host
214
+ # What Children uses from Process
215
+ interface _Host
216
+ %a{pure} def name: () -> String
217
+ %a{pure} def logger: () -> Logger
218
+ %a{pure} def monitor_children: () -> bool
219
+ %a{pure} def child_process_factory: () -> ProcessFactory::ChildFactory?
220
+ def daemonize?: () -> bool
221
+ def actual_pid: () -> Integer?
222
+ def journal: () -> ProcessJournal::Journal
223
+ end
224
+
225
+ @children: Array[Process]
226
+
227
+ def monitor_children?: () -> bool
228
+
229
+ def refresh_children!: () -> void
230
+
231
+ def add_children: (Array[Integer] child_pids) -> void
232
+
233
+ def new_child: (ProcessFactory::ChildFactory factory, Integer child_pid) -> Process
234
+ end
235
+ end
@@ -0,0 +1,21 @@
1
+ module Bluepill
2
+ # The signals that stop a process, with the delays between them
3
+ class Process::StopSignals
4
+ def self.from: (Process::StopSignals | Array[Symbol | Integer] signals) -> Process::StopSignals
5
+
6
+ attr_reader first_signal: Symbol
7
+
8
+ # Each delay, with the signal sent after it
9
+ attr_reader later_signals: Array[[Integer, Symbol]]
10
+
11
+ def initialize: (Array[Symbol | Integer] signals) -> void
12
+
13
+ def total_delay: () -> Integer
14
+
15
+ def to_a: () -> Array[Symbol | Integer]
16
+
17
+ private
18
+
19
+ def validate!: (Array[Symbol | Integer] signals) -> void
20
+ end
21
+ end