bluepill 0.1.7 → 0.2.0

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