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.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +61 -1
  3. data/CONTRIBUTING.md +2 -2
  4. data/README.md +106 -9
  5. data/bin/bluepill +25 -30
  6. data/bluepill.gemspec +21 -28
  7. data/lib/bluepill/application/lifecycle.rb +166 -0
  8. data/lib/bluepill/application/listener.rb +124 -0
  9. data/lib/bluepill/application/previous_daemon.rb +81 -0
  10. data/lib/bluepill/application.rb +56 -254
  11. data/lib/bluepill/base_directory.rb +93 -0
  12. data/lib/bluepill/clock.rb +25 -0
  13. data/lib/bluepill/condition_watch.rb +136 -58
  14. data/lib/bluepill/controller/directory.rb +59 -0
  15. data/lib/bluepill/controller.rb +99 -94
  16. data/lib/bluepill/daemonize.rb +234 -0
  17. data/lib/bluepill/dsl/app_proxy.rb +30 -6
  18. data/lib/bluepill/dsl/process_factory/children.rb +71 -0
  19. data/lib/bluepill/dsl/process_factory/registry.rb +69 -0
  20. data/lib/bluepill/dsl/process_factory.rb +81 -92
  21. data/lib/bluepill/dsl/process_proxy.rb +109 -21
  22. data/lib/bluepill/group.rb +187 -78
  23. data/lib/bluepill/logger.rb +139 -48
  24. data/lib/bluepill/pid_file.rb +23 -0
  25. data/lib/bluepill/process/attributes.rb +379 -0
  26. data/lib/bluepill/process/children.rb +70 -0
  27. data/lib/bluepill/process/pid.rb +154 -0
  28. data/lib/bluepill/process/state_machine.rb +196 -0
  29. data/lib/bluepill/process/transition.rb +45 -0
  30. data/lib/bluepill/process/transition_callbacks.rb +101 -0
  31. data/lib/bluepill/process/user_commands.rb +71 -0
  32. data/lib/bluepill/process/watches.rb +141 -0
  33. data/lib/bluepill/process.rb +60 -657
  34. data/lib/bluepill/process_commands/execution.rb +89 -0
  35. data/lib/bluepill/process_commands/hooks.rb +186 -0
  36. data/lib/bluepill/process_commands/stop_signals.rb +114 -0
  37. data/lib/bluepill/process_commands.rb +106 -174
  38. data/lib/bluepill/process_conditions/always_true.rb +1 -1
  39. data/lib/bluepill/process_conditions/below_threshold.rb +36 -0
  40. data/lib/bluepill/process_conditions/cpu_usage.rb +1 -25
  41. data/lib/bluepill/process_conditions/file_time.rb +4 -5
  42. data/lib/bluepill/process_conditions/http.rb +52 -24
  43. data/lib/bluepill/process_conditions/mem_usage.rb +9 -22
  44. data/lib/bluepill/process_conditions/process_condition.rb +34 -3
  45. data/lib/bluepill/process_conditions/running_time.rb +1 -25
  46. data/lib/bluepill/process_conditions/zombie_process.rb +1 -1
  47. data/lib/bluepill/process_conditions.rb +3 -2
  48. data/lib/bluepill/process_journal/cleanup.rb +200 -0
  49. data/lib/bluepill/process_journal/lock.rb +106 -0
  50. data/lib/bluepill/process_journal.rb +126 -233
  51. data/lib/bluepill/process_statistics.rb +2 -2
  52. data/lib/bluepill/socket.rb +60 -20
  53. data/lib/bluepill/system/command_setup.rb +98 -0
  54. data/lib/bluepill/system/commands.rb +219 -248
  55. data/lib/bluepill/system/daemon.rb +161 -0
  56. data/lib/bluepill/system/ps.rb +85 -0
  57. data/lib/bluepill/system/ps_table.rb +163 -0
  58. data/lib/bluepill/system.rb +45 -126
  59. data/lib/bluepill/trigger.rb +52 -26
  60. data/lib/bluepill/triggers/flapping.rb +8 -16
  61. data/lib/bluepill/units.rb +126 -0
  62. data/lib/bluepill/util/inflections.rb +34 -0
  63. data/lib/bluepill/util/levenshtein.rb +53 -0
  64. data/lib/bluepill/util/rotational_array.rb +1 -1
  65. data/lib/bluepill/version.rb +13 -12
  66. data/lib/bluepill.rb +33 -36
  67. data/sig/bluepill/application.rbs +257 -0
  68. data/sig/bluepill/checks.rbs +203 -0
  69. data/sig/bluepill/dsl.rbs +126 -0
  70. data/sig/bluepill/logger.rbs +104 -0
  71. data/sig/bluepill/process.rbs +542 -0
  72. data/sig/bluepill/system.rbs +316 -0
  73. data/sig/bluepill.rbs +50 -871
  74. metadata +40 -45
data/sig/bluepill.rbs CHANGED
@@ -1,9 +1,6 @@
1
1
  # Type signatures for bluepill
2
2
 
3
3
  module Bluepill
4
- # The value of Bluepill::System.ps_axu: ps fields by pid
5
- type ps_table = Hash[Integer, Array[String]]
6
-
7
4
  # A time in seconds. An ActiveSupport::Duration also works, since it
8
5
  # passes for its value.
9
6
  type seconds = Integer | Float
@@ -36,188 +33,12 @@ module Bluepill
36
33
  def self.to_s: () -> String
37
34
  end
38
35
 
39
- # The daemon: it holds the groups of processes and serves commands from
40
- # bluepill's socket
41
- class Application
42
- PROCESS_COMMANDS: Array[Symbol]
43
-
44
- DAEMON_COMMANDS: Array[Symbol]
45
-
46
- attr_accessor name: String
47
- attr_accessor logger: Logger
48
- attr_accessor base_dir: String
49
- attr_accessor socket: UNIXServer?
50
- attr_accessor pid_file: String
51
- attr_accessor kill_timeout: Integer
52
- attr_accessor groups: Hash[String?, Group]
53
- # Not used by bluepill
54
- attr_accessor work_queue: untyped
55
- attr_accessor pids_dir: String
56
- attr_accessor log_file: String?
57
-
58
- @foreground: bool?
59
- @mutex: Thread::Mutex
60
- @listener_thread: Thread?
61
- @running: bool
62
-
63
- def initialize: (String name, ?Hash[Symbol, untyped] options) -> void
64
-
65
- def foreground?: () -> bool
66
-
67
- def mutex: [T] () { () -> T } -> T
68
-
69
- def load: () -> void
70
-
71
- # The PROCESS_COMMANDS, which return the affected processes, or the
72
- # status lines for status
73
- def start: (?String? group_name, ?String? process_name) -> Array[String]
74
-
75
- def stop: (?String? group_name, ?String? process_name) -> Array[String]
76
-
77
- def restart: (?String? group_name, ?String? process_name) -> Array[String]
78
-
79
- def unmonitor: (?String? group_name, ?String? process_name) -> Array[String]
80
-
81
- def status: (?String? group_name, ?String? process_name) -> Array[String]
82
-
83
- def add_process: (Process process, ?_ToS? group_name) -> Array[Process]
84
-
85
- def version: () -> singleton(Version)
86
-
87
- # Ruby's protected methods are private in RBS
88
-
89
- private
90
-
91
- def send_to_process_or_group: (Symbol method, String? group_name, String? process_name) -> Array[String]
92
-
93
- def start_listener: () -> Thread
94
-
95
- def daemon_command: (String? command) -> Symbol
96
-
97
- def start_server: () -> void
98
-
99
- def run: () -> void
100
-
101
- def cleanup: () -> void
102
-
103
- def setup_signal_traps: () -> void
104
-
105
- def setup_logger_and_pids_dir: () -> void
106
-
107
- def setup_pids_dir: () -> void
108
-
109
- def kill_previous_bluepill: () -> void
110
-
111
- def write_pid_file: () -> void
112
- end
113
-
114
- # Runs the bluepill commands, and sends them to the daemon over its socket
115
- class Controller
116
- attr_accessor base_dir: String
117
- attr_accessor log_file: String?
118
- attr_accessor sockets_dir: String
119
- attr_accessor pids_dir: String
120
-
121
- def initialize: (Hash[Symbol, untyped] options) -> void
122
-
123
- def running_applications: () -> Array[String]
124
-
125
- def handle_command: (String application, String | Symbol command, *String args) -> void
126
-
127
- # Returns what the daemon responds with, which is unmarshaled from the socket
128
- def send_to_daemon: (String application, String | Symbol command, *String args) -> untyped
129
-
130
- def grep_pattern: (String application, ?String? query) -> String
131
-
132
- private
133
-
134
- def cleanup_bluepill_directory: () -> void
135
-
136
- def pid_for: (String app) -> (Integer | false)
137
-
138
- def setup_dir_structure: () -> void
139
-
140
- def verify_version!: (String application) -> void
141
- end
142
-
143
- module Socket
144
- TIMEOUT: Integer
145
- MAX_ATTEMPTS: Integer
146
-
147
- def self.client: [T] (String base_dir, String name) { (UNIXSocket socket) -> T } -> T
148
-
149
- # Returns the daemon's response, unmarshaled
150
- def self.client_command: (String base_dir, String name, String command) -> untyped
151
-
152
- def self.server: (String base_dir, String name) -> UNIXServer
153
-
154
- def self.socket_path: (String base_dir, String name) -> String
155
- end
156
-
157
- # Runs commands for a Process, which is the only class that includes it
158
- module ProcessCommands : _Host
159
- # What ProcessCommands uses from Process
160
- interface _Host
161
- %a{pure} def name: () -> String
162
- %a{pure} def logger: () -> Logger
163
- %a{pure} def children: () -> Array[Process]
164
- %a{pure} def pre_start_command: () -> String?
165
- %a{pure} def start_command: () -> String?
166
- %a{pure} def stop_command: () -> String?
167
- %a{pure} def restart_command: () -> String?
168
- %a{pure} def stop_signals: () -> Array[Symbol | Integer]?
169
- %a{pure} def start_grace_time: () -> seconds
170
- %a{pure} def stop_grace_time: () -> seconds
171
- %a{pure} def restart_grace_time: () -> seconds
172
- %a{pure} def on_start_timeout: () -> (String | Symbol)
173
- %a{pure} def monitor_children: () -> bool
174
- %a{pure} def uid: () -> String?
175
- %a{pure} def gid: () -> String?
176
- %a{pure} def working_dir: () -> String?
177
- %a{pure} def environment: () -> Hash[_ToS, _ToS]?
178
- %a{pure} def pid_file: () -> String?
179
- %a{pure} def stdin: () -> String?
180
- %a{pure} def stdout: () -> String?
181
- %a{pure} def stderr: () -> String?
182
- %a{pure} def supplementary_groups: () -> Array[String]?
183
- def daemonize?: () -> bool
184
- def monitor_children?: () -> bool
185
- def actual_pid: () -> Integer?
186
- def clean_threads: () -> void
187
- def signal_process: (Integer | String | Symbol code) -> bool
188
- def unlink_pid: () -> void
189
- def clear_pid: () -> void
190
- def skip_ticks_for: (seconds seconds) -> Integer
191
- def dispatch!: (Symbol | String event, ?String? reason) -> bool
192
- end
193
-
194
- @threads: Array[Thread]
195
-
196
- def start_process: () -> Integer
197
-
198
- def pre_start_process: () -> void
199
-
200
- def stop_process: () -> Integer
201
-
202
- def restart_process: () -> Integer
203
-
204
- def cleanup_process: () -> void
205
-
206
- def prepare_command: (String command) -> String
207
-
208
- def system_command_options: () -> System::command_options
209
-
210
- # Runs the block, and dispatches next_state if it takes longer than secs
211
- def with_timeout: [T] (seconds secs, String | Symbol next_state) { (Numeric secs) -> T } -> (T | bool)
212
-
213
- def run_command: (String cmd, String description) -> void
214
-
215
- def send_stop_signals: (Array[Symbol | Integer] signals) -> void
216
-
217
- def wait_for_stop: (seconds seconds) -> void
36
+ # The monotonic clock that times ticks, checks and grace times
37
+ module Clock
38
+ def self.now: () -> Integer
218
39
  end
219
40
 
220
- # What state_machine passes to transition callbacks and triggers
41
+ # What a process passes to its transition callbacks and triggers
221
42
  interface _Transition
222
43
  def from_name: () -> Symbol?
223
44
 
@@ -226,711 +47,59 @@ module Bluepill
226
47
  def loopback?: () -> bool
227
48
  end
228
49
 
229
- # A monitored process
230
- class Process
231
- include ProcessCommands
232
-
233
- CONFIGURABLE_ATTRIBUTES: Array[Symbol]
234
-
235
- attr_accessor name: String
236
- attr_accessor watches: Array[ConditionWatch]
237
- attr_accessor triggers: Array[Trigger]
238
- attr_accessor skip_ticks_until: Integer?
239
- attr_accessor process_running: bool?
240
-
241
- # CONFIGURABLE_ATTRIBUTES
242
- attr_accessor pre_start_command: String?
243
- attr_accessor start_command: String?
244
- attr_accessor stop_command: String?
245
- attr_accessor restart_command: String?
246
- attr_accessor stdout: String?
247
- attr_accessor stderr: String?
248
- attr_accessor stdin: String?
249
- attr_accessor daemonize: bool?
250
- attr_accessor pid_file: String?
251
- attr_accessor working_dir: String?
252
- attr_accessor environment: Hash[_ToS, _ToS]?
253
- attr_accessor start_grace_time: seconds
254
- attr_accessor stop_grace_time: seconds
255
- attr_accessor restart_grace_time: seconds
256
- attr_accessor uid: String?
257
- attr_accessor gid: String?
258
- attr_accessor cache_actual_pid: bool
259
- attr_accessor monitor_children: bool
260
- attr_accessor child_process_factory: ProcessFactory?
261
- attr_accessor pid_command: String?
262
- attr_accessor auto_start: bool?
263
- attr_accessor supplementary_groups: Array[String]?
264
- # Signal names alternating with delays in seconds
265
- attr_accessor stop_signals: Array[Symbol | Integer]?
266
- attr_accessor on_start_timeout: String | Symbol
267
- attr_accessor group_start_noblock: bool
268
- attr_accessor group_restart_noblock: bool
269
- attr_accessor group_stop_noblock: bool
270
- attr_accessor group_unmonitor_noblock: bool
271
-
272
- attr_reader children: Array[Process]
273
- attr_reader statistics: ProcessStatistics
274
- attr_reader logger: Logger
275
-
276
- @event_mutex: Monitor
277
- @threads: Array[Thread]
278
- @actual_pid: Integer?
279
- @transitioned: bool
280
-
281
- # Methods that state_machine defines, in a module it includes
282
- interface _StateMachine
283
- def state: () -> String
284
-
285
- def state=: (String state) -> String
286
-
287
- def state_name: () -> Symbol
288
-
289
- def human_state_name: () -> String
290
-
291
- def state?: (Symbol state) -> bool
292
-
293
- def unmonitored?: () -> bool
294
-
295
- def up?: () -> bool
296
-
297
- def down?: () -> bool
298
-
299
- def starting?: () -> bool
300
-
301
- def stopping?: () -> bool
302
-
303
- def restarting?: () -> bool
304
-
305
- def state_events: () -> Array[Symbol]
306
-
307
- def state_transitions: () -> Array[_Transition]
308
-
309
- def fire_state_event: (Symbol | String event) -> bool
310
-
311
- def can_tick?: () -> bool
312
-
313
- def tick_transition: () -> _Transition?
314
-
315
- def tick!: () -> true
316
-
317
- def start: () -> bool
318
-
319
- def can_start?: () -> bool
320
-
321
- def start_transition: () -> _Transition?
322
-
323
- def start!: () -> true
324
-
325
- def stop: () -> bool
326
-
327
- def can_stop?: () -> bool
328
-
329
- def stop_transition: () -> _Transition?
330
-
331
- def stop!: () -> true
332
-
333
- def unmonitor: () -> bool
334
-
335
- def can_unmonitor?: () -> bool
336
-
337
- def unmonitor_transition: () -> _Transition?
338
-
339
- def unmonitor!: () -> true
340
-
341
- def restart: () -> bool
342
-
343
- def can_restart?: () -> bool
344
-
345
- def restart_transition: () -> _Transition?
346
-
347
- def restart!: () -> true
348
- end
349
-
350
- include _StateMachine
351
-
352
- # Methods bluepill defines
353
-
354
- def initialize: (String process_name, Hash[Symbol, Hash[Symbol, untyped]] checks, ?Hash[Symbol, untyped] options) -> void
355
-
356
- # Runs the state machine's tick event, then the watches and children
357
- def tick: () -> void
358
-
359
- def logger=: (Logger logger) -> void
360
-
361
- def dispatch!: (Symbol | String event, ?String? reason) -> bool
362
-
363
- def record_transition: (_Transition transition) -> void
364
-
365
- def notify_triggers: (_Transition transition) -> void
366
-
367
- def add_watch: (Symbol name, Hash[Symbol, untyped] options) -> Array[ConditionWatch]
368
-
369
- def add_trigger: (Symbol name, Hash[Symbol, untyped] options) -> Array[Trigger]
370
-
371
- def run_watches: () -> void
372
-
373
- def determine_initial_state: () -> void
374
-
375
- def handle_user_command: (String cmd) -> void
376
-
377
- def process_running?: (?bool force) -> bool
378
-
379
- def clean_threads: () -> void
380
-
381
- def daemonize?: () -> bool
382
-
383
- def monitor_children?: () -> bool
384
-
385
- def signal_process: (Integer | String | Symbol code) -> bool
386
-
387
- def cache_actual_pid?: () -> bool
388
-
389
- def actual_pid: () -> Integer?
390
-
391
- def pid_from_file: () -> Integer?
392
-
393
- def pid_from_command: () -> Integer?
394
-
395
- def positive_pid: (Integer pid) -> Integer?
396
-
397
- def actual_pid=: (Integer pid) -> void
398
-
399
- def clear_pid: () -> nil
400
-
401
- def unlink_pid: () -> void
402
-
403
- def skip_ticks_for: (seconds seconds) -> Integer
404
-
405
- def skipping_ticks?: () -> bool?
406
-
407
- def refresh_children!: () -> void
408
- end
409
-
410
- # Keeps a short history of a process's events
411
- class ProcessStatistics
412
- type event = [Symbol | String, String?, Time]
413
-
414
- STRFTIME: String
415
- EVENTS_TO_PERSIST: Integer
416
-
417
- attr_reader events: Util::RotationalArray[event]
418
-
419
- def initialize: () -> void
420
-
421
- def record_event: (Symbol | String event, String? reason) -> Util::RotationalArray[event]
422
-
423
- def to_s: () -> String
50
+ # The durations and sizes a config writes, as plain numbers of seconds
51
+ # and bytes. Numeric includes it, so its own methods come first.
52
+ # What Units needs of the number it's in
53
+ interface _Multipliable
54
+ def *: (Integer) -> Numeric
424
55
  end
425
56
 
426
- # Processes that share a group name. Processes without one are in the
427
- # group named nil.
428
- class Group
429
- attr_accessor name: String?
430
- attr_accessor processes: Array[Process]
431
- attr_accessor logger: Logger
432
- # Not used by bluepill
433
- attr_accessor process_logger: untyped
434
-
435
- def initialize: (String? name, ?{ ?logger: Logger } options) -> void
436
-
437
- def add_process: (Process process) -> Array[Process]
57
+ module Units : _Multipliable
58
+ MINUTE: Integer
59
+ HOUR: Integer
60
+ DAY: Integer
61
+ KILOBYTE: Integer
62
+ MEGABYTE: Integer
63
+ GIGABYTE: Integer
438
64
 
439
- def tick: () -> void
65
+ def seconds: () -> self
66
+ alias second seconds
440
67
 
441
- def determine_initial_state: () -> void
68
+ def minutes: () -> Numeric
69
+ alias minute minutes
442
70
 
443
- # Proxied events, which return the affected processes as group:process
71
+ def hours: () -> Numeric
72
+ alias hour hours
444
73
 
445
- def start: (?String? process_name) -> Array[String]
74
+ def days: () -> Numeric
75
+ alias day days
446
76
 
447
- def unmonitor: (?String? process_name) -> Array[String]
77
+ def kilobytes: () -> Numeric
78
+ alias kilobyte kilobytes
448
79
 
449
- def stop: (?String? process_name) -> Array[String]
80
+ def megabytes: () -> Numeric
81
+ alias megabyte megabytes
450
82
 
451
- def restart: (?String? process_name) -> Array[String]
452
-
453
- def status: (?String? process_name) -> Array[String]
83
+ def gigabytes: () -> Numeric
84
+ alias gigabyte gigabytes
454
85
  end
455
86
 
456
- # Logs to a file or syslog, with nested prefixes
457
- class Logger
458
- # Where a Logger without a parent logger writes: a LoggerAdapter, or
459
- # Syslog
460
- interface _Backend
461
- def emerg: (String message) -> void
462
-
463
- def alert: (String message) -> void
464
-
465
- def crit: (String message) -> void
466
-
467
- def err: (String message) -> void
468
-
469
- def warning: (String message) -> void
470
-
471
- def notice: (String message) -> void
472
-
473
- def info: (String message) -> void
474
-
475
- def debug: (String message) -> void
476
- end
477
-
478
- type options = {
479
- ?logger: Logger,
480
- ?prefix: String?,
481
- ?stdout: bool,
482
- ?log_file: String?,
483
- ?identity: String
484
- }
485
-
486
- LOG_METHODS: Array[Symbol]
487
-
488
- # A ::Logger that also answers to the syslog method names
489
- class LoggerAdapter < ::Logger
490
- LOGGER_EQUIVALENTS: Hash[Symbol, Symbol]
491
-
492
- alias err error
493
-
494
- alias warning warn
495
-
496
- alias emerg fatal
497
-
498
- alias alert warn
499
-
500
- alias crit fatal
501
-
502
- alias notice info
503
- end
504
-
505
- @options: options
506
- @logger: Logger | (Object & _Backend)
507
- @prefix: String?
508
- @stdout: bool?
509
- @prefixes: Hash[String?, Logger]
510
-
511
- def initialize: (?options options) -> void
512
-
513
- def emerg: (_ToS msg, ?Array[String?] prefix) -> void
514
-
515
- def alert: (_ToS msg, ?Array[String?] prefix) -> void
516
-
517
- def crit: (_ToS msg, ?Array[String?] prefix) -> void
518
-
519
- def err: (_ToS msg, ?Array[String?] prefix) -> void
520
-
521
- def warning: (_ToS msg, ?Array[String?] prefix) -> void
522
-
523
- def notice: (_ToS msg, ?Array[String?] prefix) -> void
524
-
525
- def info: (_ToS msg, ?Array[String?] prefix) -> void
526
-
527
- def debug: (_ToS msg, ?Array[String?] prefix) -> void
528
-
529
- def prefix_with: (String? prefix) -> Logger
530
-
531
- def reopen: () -> void
532
-
533
- private
534
-
535
- def create_logger: () -> (Object & _Backend)
536
-
537
- def require_syslog: () -> void
538
- end
539
-
540
- # A value a ConditionWatch got, and whether it passed the check
541
- class HistoryValue < Struct[_ToS]
542
- attr_accessor value: _ToS
543
- attr_accessor critical: bool
544
-
545
- def self.new: (_ToS value, bool critical) -> HistoryValue
546
- end
547
-
548
- # Runs a process condition every so often, and fires its events when the
549
- # check fails often enough
550
- class ConditionWatch
551
- EMPTY_ARRAY: Array[Symbol]
552
-
553
- attr_accessor logger: Logger
554
- attr_accessor name: Symbol
555
-
556
- @fires: Array[Symbol]
557
- @every: Integer
558
- @times: Array[Integer]
559
- @include_children: bool
560
- @history: Util::RotationalArray[HistoryValue]
561
- @process_condition: ProcessConditions::ProcessCondition[untyped]
562
- @last_ran_at: Integer?
563
-
564
- def initialize: (Symbol name, ?Hash[Symbol, untyped] options) -> void
565
-
566
- # Returns the events to fire
567
- def run: (Integer? pid, ?Integer tick_number) -> Array[Symbol]
568
-
569
- def clear_history!: () -> Util::RotationalArray[HistoryValue]
570
-
571
- def fired?: () -> bool
572
-
573
- def to_s: () -> String
574
- end
575
-
576
- # Reacts to a process's state transitions. Subclasses register themselves
577
- # by their underscored name.
578
- class Trigger
579
- self.@implementations: Hash[Symbol, singleton(Trigger)]
580
-
581
- def self.inherited: (singleton(Trigger) klass) -> void
582
-
583
- def self.[]: %a{implicitly-returns-nil} (Symbol name) -> singleton(Trigger)
584
-
585
- attr_accessor process: Process
586
- attr_accessor logger: Logger
587
- attr_accessor mutex: Thread::Mutex
588
- attr_accessor scheduled_events: Array[[Symbol, Thread]]
589
-
590
- def initialize: (Process process, ?Hash[Symbol, untyped] options) -> void
591
-
592
- def reset!: () -> void
593
-
594
- def notify: (_Transition transition) -> void
595
-
596
- def dispatch!: (Symbol event) -> bool
597
-
598
- def schedule_event: (Symbol event, seconds delay) -> Thread
599
-
600
- def cancel_all_events: () -> void
601
- end
602
-
603
- module Triggers
604
- # Unmonitors a process that starts or restarts too often, and starts it
605
- # again later
606
- class Flapping < Trigger
607
- TRIGGER_STATES: Array[Symbol]
608
- PARAMS: Array[Symbol]
609
-
610
- attr_accessor times: Integer
611
- attr_accessor within: Integer
612
- attr_accessor retry_in: Integer
613
- attr_reader timeline: Util::RotationalArray[Integer]
614
-
615
- def initialize: (Process process, ?Hash[Symbol, untyped] options) -> void
616
-
617
- def notify: (_Transition transition) -> void
618
-
619
- def reset!: () -> void
620
-
621
- def check_flapping: () -> void
622
- end
623
- end
624
-
625
- # self in an application block
626
- class AppProxy
627
- APP_ATTRIBUTES: Array[Symbol]
628
-
629
- attr_accessor working_dir: String?
630
- attr_accessor uid: String?
631
- attr_accessor gid: String?
632
- attr_accessor environment: Hash[_ToS, _ToS]?
633
- attr_accessor auto_start: bool?
634
- attr_reader app: Application
635
-
636
- def initialize: (_ToS app_name, Hash[Symbol, untyped] options) -> void
637
-
638
- # The block runs with self set to the ProcessProxy, and also gets it as
639
- # an argument
640
- def process: (String process_name) { (ProcessProxy process) [self: ProcessProxy] -> void } -> Array[Process]
641
- end
642
-
643
- # Builds processes from a process block in the config
644
- class ProcessFactory
645
- @@process_keys: Hash[Array[String?], nil]
646
- @@pid_files: Hash[String, nil]
647
-
648
- @process_block: process_block
649
-
650
- attr_reader attributes: Hash[Symbol, untyped]
651
-
652
- def initialize: (Hash[Symbol, untyped] attributes, process_block process_block) -> void
87
+ module Util
88
+ # Turns a snake_case name into CamelCase, as ActiveSupport's camelize
89
+ # does
90
+ def self.camelize: (_ToS name) -> String
653
91
 
654
- def create_process: (String name, String pids_dir) -> Process
92
+ # Turns a CamelCase name into snake_case, as ActiveSupport's underscore
93
+ # does
94
+ def self.underscore: (String name) -> String
655
95
 
656
- def create_child_process: (String name, Integer pid, Logger logger) -> Process
96
+ # The Levenshtein distance between two strings
97
+ def self.levenshtein_distance: (String from, String to) -> Integer
657
98
 
658
99
  private
659
100
 
660
- def assign_default_pid_file: (String process_name, String pids_dir) -> String?
661
-
662
- def validate_process!: (ProcessProxy process) -> void
663
-
664
- def validate_unique_process!: (ProcessProxy process) -> void
665
-
666
- def validate_required_attributes!: (ProcessProxy process) -> void
667
-
668
- def validate_unique_pid_file!: () -> void
669
-
670
- def validate_stop_signals!: () -> void
671
-
672
- def warn_unless_pid_known: (ProcessProxy process, String? default_pid_file) -> void
673
-
674
- def config_error!: (String message) -> bot
675
-
676
- def validate_child_process!: (ProcessProxy child) -> void
677
- end
678
-
679
- # self in a process block. Any attribute can be set with `name = value`,
680
- # `name value` or `name!` (for true), and read back with `name`.
681
- class ProcessProxy
682
- attr_reader attributes: Hash[Symbol, untyped]
683
- attr_reader watches: Hash[Symbol, Hash[Symbol, untyped]]
684
- attr_reader name: String
685
-
686
- def initialize: (String process_name, Hash[Symbol, untyped] attributes, process_block process_block) -> void
687
-
688
- # Sets or reads an attribute
689
- def method_missing: (Symbol name, *untyped args) -> untyped
690
-
691
- def respond_to_missing?: (Symbol name, bool? include_private) -> bool
692
-
693
- def checks: (Symbol name, ?Hash[Symbol, untyped] options) -> Hash[Symbol, untyped]
694
-
695
- # The block configures the children like a process block
696
- def monitor_children: () ?{ (ProcessProxy child) [self: ProcessProxy] -> void } -> process_block?
697
-
698
- def to_process: () -> Process
699
- end
700
-
701
- # Memoizes ps output for a tick, and runs commands as daemons or until
702
- # they finish
703
- module System
704
- # Options for daemonize and execute_blocking
705
- type command_options = {
706
- ?uid: String?,
707
- ?gid: String?,
708
- ?working_dir: String?,
709
- ?environment: Hash[_ToS, _ToS]?,
710
- ?pid_file: String?,
711
- ?logger: Logger,
712
- ?stdin: String?,
713
- ?stdout: String?,
714
- ?stderr: String?,
715
- ?supplementary_groups: Array[String]?
716
- }
717
-
718
- type blocking_result = { exit_code: Integer?, stdout: String, stderr: String }
719
-
720
- type grandchild_pipes = { out: [IO, IO], err: [IO, IO], result: IO }
721
-
722
- APPEND_MODE: String
723
-
724
- IDX_MAP: { pid: Integer, ppid: Integer, pcpu: Integer, rss: Integer, etime: Integer, command: Integer }
725
-
726
- PS_MUTEX: Thread::Mutex
727
-
728
- # The store lives on the module. Steep checks the module functions as
729
- # instance methods, so it needs the instance variable too.
730
- self.@store: Hash[Symbol, ps_table | String]
731
- @store: Hash[Symbol, ps_table | String]
732
-
733
- # Raised when ps could not be run, so there is no data for this tick
734
- class PsError < StandardError
735
- end
736
-
737
- def self.pid_alive?: (Integer pid) -> bool
738
-
739
- def self.started_at: (Integer pid) -> Integer?
740
-
741
- def self.boot_time: () -> Integer?
742
-
743
- def self.cpu_usage: (Integer? pid, boolish include_children) -> Float?
744
-
745
- def self.memory_usage: (Integer? pid, boolish include_children) -> Float?
746
-
747
- def self.running_time: (Integer? pid) -> Integer?
748
-
749
- def self.command: (Integer? pid) -> String?
750
-
751
- def self.get_children: (Integer? parent_pid) -> Array[Integer]
752
-
753
- def self.delete_if_exists: (String? filename) -> void
101
+ def self.next_levenshtein_row!: (Array[Integer] row, Integer from_length, String from_char, String to) -> void
754
102
 
755
- def self.store: () -> Hash[Symbol, ps_table | String]
756
-
757
- def self.reset_data: () -> void
758
-
759
- def self.ps_axu: () -> ps_table
760
-
761
- def self.parse_elapsed_time: (String? str) -> Integer
762
-
763
- # Returns the daemon's pid
764
- def self.daemonize: (String cmd, ?command_options options) -> Integer?
765
-
766
- def self.execute_blocking: (String cmd, ?command_options options) -> blocking_result
767
-
768
- def self.run_blocking_child: (String cmd, command_options options, IO result_pipe) -> bot
769
-
770
- def self.exec_blocking_grandchild: (String cmd, command_options options, grandchild_pipes pipes) -> bot
771
-
772
- def self.setup_command_environment: (command_options options) -> void
773
-
774
- def self.drop_privileges: (String? uid, String? gid, Array[String]? supplementary_groups) -> void
775
-
776
- def self.can_write_pid_file: (String pid_file, Logger logger) -> bool
777
-
778
- def self.redirect_io: (String? io_in, String? io_out, String? io_err) -> void
779
- end
780
-
781
- # Remembers the pids and process groups of the processes bluepill starts,
782
- # so it can kill any left over from an earlier run
783
- module ProcessJournal
784
- self.@logger: Logger
785
- self.@journal_base_dir: String
786
- self.@legacy_journal_dir: String
787
-
788
- def self.logger: () -> Logger
789
-
790
- def self.journal_base_dir: () -> String
791
-
792
- def self.legacy_journal_dir: () -> String
793
-
794
- # Only the first logger is kept
795
- def self.logger=: (Logger new_logger) -> Logger
796
-
797
- def self.setup: (String base_dir, _ToS app_name) -> void
798
-
799
- def self.skip_pid?: (Integer? pid) -> bool
800
-
801
- def self.skip_pgid?: (Integer? pgid) -> bool
802
-
803
- def self.acquire_atomic_fs_lock: [T] (String name) { () -> T } -> T
804
-
805
- def self.clear_all_atomic_fs_locks: () -> void
806
-
807
- def self.pid_journal_filename: (String journal_name, ?String dir) -> String
808
-
809
- def self.pgid_journal_filename: (String journal_name, ?String dir) -> String
810
-
811
- # Each id, with when its process started (nil before 0.2)
812
- def self.journal_entries: (String filename) -> Array[[Integer, Integer?]]
813
-
814
- def self.journal_line: (Integer id) -> String
815
-
816
- def self.pid_journal: (String filename) -> Array[Integer]
817
-
818
- def self.pgid_journal: (String filename) -> Array[Integer]
819
-
820
- def self.clear_atomic_fs_lock: (String name) -> void
821
-
822
- def self.kill_all_from_journal: (String journal_name) -> void
823
-
824
- def self.kill_all_pgids_from_journal: (String journal_name) -> void
825
-
826
- def self.kill_all_pids_from_journal: (String journal_name) -> void
827
-
828
- def self.journal_dirs: () -> Array[String]
829
-
830
- def self.kill_all_from_journal_file: (String filename, Array[Integer] ids, String label, Integer sign) -> void
831
-
832
- def self.journaled_ids: (String filename, Array[Integer] ids, String label) -> Array[Integer]
833
-
834
- def self.signal_journaled: (String signal, Array[Integer] ids, String label, Integer sign) -> void
835
-
836
- def self.append_pgid_to_journal: (String journal_name, Integer? pgid) -> void
837
-
838
- def self.append_pid_to_journal: (String journal_name, Integer? pid) -> void
839
- end
840
-
841
- module ProcessConditions
842
- def self.[]: (Symbol | String name) -> singleton(ProcessCondition)
843
-
844
- # Checks something about a process. V is the type of value that run
845
- # returns and check tests.
846
- class ProcessCondition[V]
847
- @options: Hash[Symbol, untyped]
848
-
849
- def initialize: (?Hash[Symbol, untyped] options) -> void
850
-
851
- def run: (Integer? pid, boolish include_children) -> V
852
-
853
- # Whether the value is fine
854
- def check: (V value) -> bool
855
-
856
- def format_value: (V value) -> V
857
- end
858
-
859
- class AlwaysTrue < ProcessCondition[Integer]
860
- def run: (Integer? pid, boolish include_children) -> Integer
861
-
862
- def check: (Integer value) -> true
863
- end
864
-
865
- class CpuUsage < ProcessCondition[Float]
866
- @below: Numeric
867
-
868
- def run: (Integer? pid, boolish include_children) -> Float
869
-
870
- def check: (Float value) -> bool
871
- end
872
-
873
- # Seconds since the file changed, or the error that stopped bluepill
874
- # from finding out
875
- class FileTime < ProcessCondition[Float | StandardError | nil]
876
- @below: Numeric
877
- @filename: String
878
-
879
- def run: (Integer? pid, boolish include_children) -> (Float | StandardError | nil)
880
-
881
- def check: (Float | StandardError | nil value) -> bool
882
- end
883
-
884
- class Http < ProcessCondition[Net::HTTPResponse | StandardError]
885
- @uri: URI::HTTP
886
- @kind: Class
887
- @pattern: Regexp?
888
- @open_timeout: Integer
889
- @read_timeout: Integer
890
-
891
- def run: (Integer? pid, boolish include_children) -> (Net::HTTPResponse | StandardError)
892
-
893
- def check: (Net::HTTPResponse | StandardError value) -> bool
894
-
895
- private
896
-
897
- def hide_net_http_bug: [T] () { () -> T } -> T
898
- end
899
-
900
- # Memory usage in kilobytes
901
- class MemUsage < ProcessCondition[Float]
902
- MB: Integer
903
- FORMAT_STR: String
904
- MB_LABEL: String
905
- KB_LABEL: String
906
-
907
- @below: Numeric
908
-
909
- def run: (Integer? pid, boolish include_children) -> Float
910
-
911
- def check: (Float value) -> bool
912
-
913
- def format_value: (Float value) -> String
914
- end
915
-
916
- # Seconds since the process started
917
- class RunningTime < ProcessCondition[Integer]
918
- @below: Numeric
919
-
920
- def run: (Integer? pid, boolish include_children) -> Integer
921
-
922
- def check: (Integer value) -> bool
923
- end
924
-
925
- # The process's command line, which says <defunct> for a zombie
926
- class ZombieProcess < ProcessCondition[String?]
927
- def run: (Integer? pid, boolish include_children) -> String?
928
-
929
- def check: (String? value) -> bool
930
- end
931
- end
932
-
933
- module Util
934
103
  # An array that drops its oldest element when it grows past its capacity
935
104
  class RotationalArray[Elem] < Array[Elem]
936
105
  @capacity: Integer
@@ -943,3 +112,13 @@ module Bluepill
943
112
  end
944
113
  end
945
114
  end
115
+
116
+ # Numeric includes Units, so these do. Numeric itself has no * to type it
117
+ # with.
118
+ class Integer
119
+ include Bluepill::Units
120
+ end
121
+
122
+ class Float
123
+ include Bluepill::Units
124
+ end