bluepill 0.2.7 → 0.3.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 (89) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +144 -1
  3. data/README.md +17 -10
  4. data/bin/bluepill +8 -2
  5. data/bluepill.gemspec +1 -1
  6. data/lib/bluepill/application/lifecycle.rb +43 -31
  7. data/lib/bluepill/application/listener.rb +1 -1
  8. data/lib/bluepill/application/previous_daemon.rb +14 -14
  9. data/lib/bluepill/application.rb +48 -28
  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 +61 -67
  14. data/lib/bluepill/controller/directory.rb +1 -3
  15. data/lib/bluepill/controller.rb +46 -38
  16. data/lib/bluepill/dsl/app_proxy.rb +69 -58
  17. data/lib/bluepill/dsl/attributes.rb +135 -0
  18. data/lib/bluepill/dsl/process_factory/child_factory.rb +80 -0
  19. data/lib/bluepill/dsl/process_factory/registry.rb +6 -26
  20. data/lib/bluepill/dsl/process_factory.rb +86 -70
  21. data/lib/bluepill/dsl/process_proxy.rb +61 -158
  22. data/lib/bluepill/dsl.rb +15 -6
  23. data/lib/bluepill/errors.rb +190 -0
  24. data/lib/bluepill/group.rb +14 -37
  25. data/lib/bluepill/logger.rb +55 -97
  26. data/lib/bluepill/process/attributes.rb +66 -32
  27. data/lib/bluepill/process/children.rb +4 -6
  28. data/lib/bluepill/process/pid.rb +41 -35
  29. data/lib/bluepill/process/state_machine.rb +15 -59
  30. data/lib/bluepill/process/stop_signals.rb +120 -0
  31. data/lib/bluepill/process/transition.rb +1 -3
  32. data/lib/bluepill/process/transition_callbacks.rb +2 -19
  33. data/lib/bluepill/process/triggers.rb +90 -0
  34. data/lib/bluepill/process/user_commands.rb +1 -1
  35. data/lib/bluepill/process/watches.rb +9 -23
  36. data/lib/bluepill/process.rb +70 -55
  37. data/lib/bluepill/process_commands/execution.rb +14 -22
  38. data/lib/bluepill/process_commands/hooks.rb +1 -31
  39. data/lib/bluepill/process_commands/stop_signals.rb +12 -17
  40. data/lib/bluepill/process_commands.rb +10 -8
  41. data/lib/bluepill/process_conditions/always_true.rb +2 -6
  42. data/lib/bluepill/process_conditions/below_threshold.rb +6 -8
  43. data/lib/bluepill/process_conditions/cpu_usage.rb +1 -4
  44. data/lib/bluepill/process_conditions/file_time.rb +8 -9
  45. data/lib/bluepill/process_conditions/http.rb +28 -43
  46. data/lib/bluepill/process_conditions/mem_usage.rb +7 -45
  47. data/lib/bluepill/process_conditions/process_condition.rb +30 -32
  48. data/lib/bluepill/process_conditions/zombie_process.rb +2 -6
  49. data/lib/bluepill/process_conditions.rb +5 -14
  50. data/lib/bluepill/process_journal/cleanup.rb +5 -53
  51. data/lib/bluepill/process_journal/config.rb +73 -0
  52. data/lib/bluepill/process_journal/entries.rb +128 -0
  53. data/lib/bluepill/process_journal/journal.rb +69 -0
  54. data/lib/bluepill/process_journal/kind.rb +60 -0
  55. data/lib/bluepill/process_journal/lock.rb +9 -4
  56. data/lib/bluepill/process_journal.rb +13 -324
  57. data/lib/bluepill/process_statistics.rb +3 -7
  58. data/lib/bluepill/socket.rb +19 -17
  59. data/lib/bluepill/system/command_options.rb +135 -0
  60. data/lib/bluepill/system/command_result.rb +73 -0
  61. data/lib/bluepill/system/command_setup.rb +3 -4
  62. data/lib/bluepill/system/commands.rb +21 -18
  63. data/lib/bluepill/system/daemon.rb +19 -14
  64. data/lib/bluepill/system/files.rb +35 -0
  65. data/lib/bluepill/system/ps.rb +20 -17
  66. data/lib/bluepill/system/ps_table.rb +7 -9
  67. data/lib/bluepill/system/usage.rb +155 -0
  68. data/lib/bluepill/system.rb +7 -192
  69. data/lib/bluepill/trigger.rb +22 -32
  70. data/lib/bluepill/triggers/flapping.rb +12 -8
  71. data/lib/bluepill/units.rb +7 -21
  72. data/lib/bluepill/util/log_error.rb +28 -0
  73. data/lib/bluepill/version.rb +12 -22
  74. data/lib/bluepill.rb +1 -0
  75. data/sig/bluepill/application.rbs +17 -12
  76. data/sig/bluepill/attributes.rbs +48 -0
  77. data/sig/bluepill/checks.rbs +43 -30
  78. data/sig/bluepill/dsl.rbs +98 -55
  79. data/sig/bluepill/errors.rbs +48 -0
  80. data/sig/bluepill/logger.rbs +15 -31
  81. data/sig/bluepill/process.rbs +42 -304
  82. data/sig/bluepill/process_commands.rbs +235 -0
  83. data/sig/bluepill/stop_signals.rbs +21 -0
  84. data/sig/bluepill/system.rbs +154 -99
  85. data/sig/bluepill/version.rbs +17 -0
  86. data/sig/bluepill.rbs +4 -17
  87. data/sig/manifest.yaml +1 -0
  88. metadata +22 -3
  89. data/lib/bluepill/dsl/process_factory/children.rb +0 -73
@@ -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
@@ -33,26 +33,68 @@ module Bluepill
33
33
  # they finish
34
34
  module System
35
35
  extend Ps
36
+ extend Usage
37
+ extend Files
36
38
  extend Commands
37
39
  extend Daemon
38
40
 
39
- # Options for daemonize and execute_blocking
40
- type command_options = {
41
- ?uid: String?,
42
- ?gid: String?,
43
- ?working_dir: String?,
44
- ?environment: Hash[_ToS, _ToS]?,
45
- ?pid_file: String?,
46
- ?logger: Logger,
47
- ?stdin: String?,
41
+ # What the child that runs a command sends its parent
42
+ type blocking_result = { exit_code: Integer?, stdout: String, stderr: String }
43
+
44
+ # How a command runs, for daemonize and execute_blocking
45
+ class CommandOptions
46
+ attr_reader uid: String?
47
+ attr_reader gid: String?
48
+ attr_reader supplementary_groups: Array[String]?
49
+ attr_reader working_dir: String?
50
+ attr_reader environment: Hash[_ToS, _ToS]
51
+ attr_reader stdin: String?
52
+ attr_reader stdout: String?
53
+ attr_reader stderr: String?
48
54
  # Hooks are killed after this many seconds
49
- ?timeout: seconds,
50
- ?stdout: String?,
51
- ?stderr: String?,
52
- ?supplementary_groups: Array[String]?
53
- }
55
+ attr_reader timeout: seconds?
56
+
57
+ def initialize: (
58
+ ?uid: String?,
59
+ ?gid: String?,
60
+ ?supplementary_groups: Array[String]?,
61
+ ?working_dir: String?,
62
+ ?environment: Hash[_ToS, _ToS]?,
63
+ ?stdin: String?,
64
+ ?stdout: String?,
65
+ ?stderr: String?,
66
+ ?timeout: seconds?
67
+ ) -> void
68
+
69
+ def for_hook: (Hash[String, String] env, seconds timeout) -> CommandOptions
70
+
71
+ def to_h: () -> {
72
+ uid: String?,
73
+ gid: String?,
74
+ supplementary_groups: Array[String]?,
75
+ working_dir: String?,
76
+ environment: Hash[_ToS, _ToS]?,
77
+ stdin: String?,
78
+ stdout: String?,
79
+ stderr: String?,
80
+ timeout: seconds?
81
+ }
82
+ end
54
83
 
55
- type blocking_result = { exit_code: Integer?, stdout: String, stderr: String }
84
+ # What a command that ran until it finished printed, and how it exited
85
+ class CommandResult
86
+ def self.from_h: (blocking_result result) -> CommandResult
87
+
88
+ attr_reader exit_code: Integer?
89
+ attr_reader stdout: String
90
+ attr_reader stderr: String
91
+
92
+ def initialize: (exit_code: Integer?, ?stdout: String, ?stderr: String) -> void
93
+
94
+ def success?: () -> bool
95
+
96
+ def to_h: () -> blocking_result
97
+ end
56
98
 
57
99
  type grandchild_pipes = { out: [IO, IO], err: [IO, IO], result: IO }
58
100
 
@@ -101,45 +143,50 @@ module Bluepill
101
143
 
102
144
  # Runs ps once a tick, and reads its table of processes
103
145
  module Ps
104
- # The store lives on System, which extends this module
105
- @store: Hash[Symbol, PsTable | String]
146
+ # The table lives on System, which extends this module, or why ps
147
+ # could not be run this tick
148
+ @ps_table: PsTable | PsError | nil
106
149
  # The table get_children read this tick
107
150
  @children_table: PsTable?
108
151
 
109
- def store: () -> Hash[Symbol, PsTable | String]
110
-
111
152
  def reset_data: () -> void
112
153
 
113
154
  def ps_axu: () -> PsTable
114
155
 
115
- def read_ps_table: () -> (PsTable | String)
156
+ def read_ps_table: () -> (PsTable | PsError)
116
157
 
117
158
  def get_children: (Integer? parent_pid) -> Array[Integer]
118
159
  end
119
160
 
120
- def self.pid_alive?: (Integer pid) -> bool
161
+ # Asks the system about a process
162
+ module Usage : Ps
163
+ def pid_alive?: (Integer pid) -> bool
121
164
 
122
- def self.started_at: (Integer pid) -> Integer?
165
+ def started_at: (Integer pid) -> Integer?
123
166
 
124
- def self.boot_time: () -> Integer?
167
+ def boot_time: () -> Integer?
125
168
 
126
- def self.cpu_usage: (Integer? pid, boolish include_children) -> Float?
169
+ def cpu_usage: (Integer? pid, boolish include_children) -> Float?
127
170
 
128
- def self.memory_usage: (Integer? pid, boolish include_children) -> Float?
171
+ def memory_usage: (Integer? pid, boolish include_children) -> Float?
129
172
 
130
- def self.usage: (Integer? pid, boolish include_children, Integer column) -> Float?
173
+ def usage: (Integer? pid, boolish include_children, Integer column) -> Float?
131
174
 
132
- def self.running_time: (Integer? pid) -> Integer?
175
+ def running_time: (Integer? pid) -> Integer?
133
176
 
134
- def self.command: (Integer? pid) -> String?
177
+ def command: (Integer? pid) -> String?
135
178
 
136
- def self.delete_if_exists: (String? filename) -> void
179
+ def parse_elapsed_time: (String? str) -> Integer
180
+ end
137
181
 
138
- def self.parse_elapsed_time: (String? str) -> Integer
182
+ # Deletes the files that bluepill leaves behind
183
+ module Files
184
+ def delete_if_exists: (String? filename) -> void
185
+ end
139
186
 
140
187
  # Sets up the process that a command runs in
141
188
  module CommandSetup
142
- def setup_command_environment: (command_options options) -> void
189
+ def setup_command_environment: (CommandOptions options) -> void
143
190
 
144
191
  def drop_privileges: (String? uid, String? gid, Array[String]? supplementary_groups) -> void
145
192
 
@@ -155,13 +202,13 @@ module Bluepill
155
202
  include CommandSetup
156
203
 
157
204
  # Returns the daemon's pid
158
- def daemonize: (String cmd, ?command_options options) -> Integer?
205
+ def daemonize: (String cmd, ?CommandOptions options, pid_file: String, logger: Logger) -> Integer?
159
206
 
160
207
  def read_daemon_pid: (IO reader, IO writer) -> Integer?
161
208
 
162
- def start_daemon: (String cmd, command_options options, IO pid_pipe) -> bot
209
+ def start_daemon: (String cmd, CommandOptions options, IO pid_pipe, pid_file: String, logger: Logger) -> bot
163
210
 
164
- def daemon_command: (String cmd, command_options options) -> ^() -> void
211
+ def daemon_command: (String cmd, CommandOptions options) -> ^() -> void
165
212
 
166
213
  def can_write_pid_file: (String pid_file, Logger logger) -> bool
167
214
 
@@ -172,21 +219,21 @@ module Bluepill
172
219
  module Commands
173
220
  include CommandSetup
174
221
 
175
- def execute_blocking: (String cmd, ?command_options options) -> blocking_result
222
+ def execute_blocking: (String cmd, ?CommandOptions options) -> CommandResult
176
223
 
177
- def start_blocking_child: (String cmd, command_options options, IO reader, IO result_pipe) -> bot
224
+ def start_blocking_child: (String cmd, CommandOptions options, IO reader, IO result_pipe) -> bot
178
225
 
179
226
  def read_blocking_status: (String cmd, seconds? timeout, Integer child, IO reader) -> String
180
227
 
181
228
  def kill_group_after: (Integer child, seconds? timeout, String cmd) -> bot
182
229
 
183
- def run_blocking_child: (String cmd, command_options options, IO result_pipe) -> bot
230
+ def run_blocking_child: (String cmd, CommandOptions options, IO result_pipe) -> bot
184
231
 
185
232
  def collect_blocking_result: (Integer pid, IO cmd_out_read, IO cmd_err_read) -> blocking_result
186
233
 
187
234
  def report_blocking_result: (IO result_pipe, blocking_result result) -> bot
188
235
 
189
- def exec_blocking_grandchild: (String cmd, command_options options, grandchild_pipes pipes) -> bot
236
+ def exec_blocking_grandchild: (String cmd, CommandOptions options, grandchild_pipes pipes) -> bot
190
237
 
191
238
  def reopen_on_pipe: (IO stream, [IO, IO] pipe) -> void
192
239
 
@@ -197,23 +244,49 @@ module Bluepill
197
244
  # Remembers the pids and process groups of the processes bluepill starts,
198
245
  # so it can kill any left over from an earlier run
199
246
  module ProcessJournal
247
+ extend Config
248
+ extend Entries
200
249
  extend Cleanup
201
250
  extend Lock
202
251
 
203
252
  # What a journal holds: pids, or process group ids
204
- class Kind < Struct[String | Integer]
205
- attr_accessor name: String
206
- attr_accessor label: String
207
- attr_accessor file_tag: String
208
- attr_accessor sign: Integer
253
+ class Kind
254
+ @file_tag: String
255
+
256
+ attr_reader name: String
257
+ attr_reader label: String
258
+ attr_reader sign: Integer
209
259
 
210
- def self.new: (String name, String label, String file_tag, Integer sign) -> Kind
260
+ def initialize: (String name, String label, String file_tag, Integer sign) -> void
261
+
262
+ def filename: (String dir, _ToS journal_name) -> String
211
263
  end
212
264
 
213
265
  PID: Kind
214
266
 
215
267
  PGID: Kind
216
268
 
269
+ # Raised when another process holds a journal's lock for too long
270
+ class LockTimeoutError < StandardError
271
+ end
272
+
273
+ # A process's pid journal and process group journal
274
+ class Journal
275
+ @name: _ToS
276
+
277
+ attr_reader name: _ToS
278
+
279
+ def initialize: (_ToS name) -> void
280
+
281
+ def append: (Integer? pid) -> void
282
+
283
+ def kill_all: () -> void
284
+
285
+ private
286
+
287
+ def append_process_group: (Integer pid) -> void
288
+ end
289
+
217
290
  # What the modules that ProcessJournal extends use from it
218
291
  interface _Journal
219
292
  def logger: () -> Logger
@@ -222,24 +295,54 @@ module Bluepill
222
295
 
223
296
  def legacy_journal_dir: () -> String
224
297
 
225
- def journal_filename: (Kind kind, String journal_name, ?String dir) -> String
298
+ def journal_dirs: () -> Array[String]
226
299
 
227
300
  def journal_entries: (String filename) -> Array[[Integer, Integer?]]
228
301
 
229
302
  def journal_ids: (Kind kind, String filename) -> Array[Integer]
230
303
  end
231
304
 
232
- # Kills what an earlier run left in a process's journals
233
- module Cleanup : _Journal, Lock
234
- def kill_all_from_journal: (String journal_name) -> void
305
+ # Where the journals are, and the logger they write to
306
+ module Config
307
+ @logger: Logger
308
+ @journal_base_dir: String
309
+ @legacy_journal_dir: String
310
+
311
+ attr_reader logger: Logger
235
312
 
236
- def kill_all_pgids_from_journal: (String journal_name) -> void
313
+ attr_reader journal_base_dir: String
237
314
 
238
- def kill_all_pids_from_journal: (String journal_name) -> void
315
+ attr_reader legacy_journal_dir: String
239
316
 
240
- def kill_all_ids_from_journal: (Kind kind, String journal_name) -> void
317
+ # Only the first logger is kept
318
+ def logger=: (Logger new_logger) -> Logger
319
+
320
+ def setup: (String base_dir, _ToS app_name) -> void
241
321
 
242
322
  def journal_dirs: () -> Array[String]
323
+ end
324
+
325
+ # Reads and writes the ids in a process's journals
326
+ module Entries : _Journal, Lock
327
+ def for: (_ToS name) -> Journal
328
+
329
+ def skip_id?: (Integer? id) -> bool
330
+
331
+ # Each id, with when its process started (nil before 0.2)
332
+ def journal_entries: (String filename) -> Array[[Integer, Integer?]]
333
+
334
+ def journal_line: (Integer id) -> String
335
+
336
+ def journal_ids: (Kind kind, String filename) -> Array[Integer]
337
+
338
+ def append: (Kind kind, _ToS journal_name, Integer? id) ?{ (Integer id) -> void } -> void
339
+
340
+ def write_to_journal: (String filename, _ToS journal_name, String name, Integer id) { () -> Array[Integer] } -> void
341
+ end
342
+
343
+ # Kills what an earlier run left in a process's journals
344
+ module Cleanup : _Journal, Lock
345
+ def kill_all: (Kind kind, _ToS journal_name) -> void
243
346
 
244
347
  def kill_all_from_journal_file: (String filename, Array[Integer] ids, Kind kind) -> void
245
348
 
@@ -264,53 +367,5 @@ module Bluepill
264
367
 
265
368
  def wait_for_atomic_fs_lock: (String lock, Integer attempts) -> void
266
369
  end
267
-
268
- self.@logger: Logger
269
- self.@journal_base_dir: String
270
- self.@legacy_journal_dir: String
271
-
272
- def self.logger: () -> Logger
273
-
274
- def self.journal_base_dir: () -> String
275
-
276
- def self.legacy_journal_dir: () -> String
277
-
278
- # Only the first logger is kept
279
- def self.logger=: (Logger new_logger) -> Logger
280
-
281
- def self.setup: (String base_dir, _ToS app_name) -> void
282
-
283
- def self.skip_pid?: (Integer? pid) -> bool
284
-
285
- def self.skip_pgid?: (Integer? pgid) -> bool
286
-
287
- def self.skip_id?: (Integer? id) -> bool
288
-
289
- def self.pid_journal_filename: (String journal_name, ?String dir) -> String
290
-
291
- def self.pgid_journal_filename: (String journal_name, ?String dir) -> String
292
-
293
- def self.journal_filename: (Kind kind, String journal_name, ?String dir) -> String
294
-
295
- # Each id, with when its process started (nil before 0.2)
296
- def self.journal_entries: (String filename) -> Array[[Integer, Integer?]]
297
-
298
- def self.journal_line: (Integer id) -> String
299
-
300
- def self.pid_journal: (String filename) -> Array[Integer]
301
-
302
- def self.pgid_journal: (String filename) -> Array[Integer]
303
-
304
- def self.journal_ids: (Kind kind, String filename) -> Array[Integer]
305
-
306
- def self.append_pgid_to_journal: (String journal_name, Integer? pgid) -> void
307
-
308
- def self.append_pid_to_journal: (String journal_name, Integer? pid) -> void
309
-
310
- def self.append_process_group_to_journal: (String journal_name, Integer pid) -> void
311
-
312
- def self.append_to_journal: (Kind kind, String journal_name, Integer? id) ?{ (Integer id) -> void } -> void
313
-
314
- def self.write_to_journal: (String filename, String journal_name, String name, Integer id) { () -> Array[Integer] } -> void
315
370
  end
316
371
  end
@@ -0,0 +1,17 @@
1
+ module Bluepill
2
+ module Version
3
+ def self.major: () -> Integer
4
+
5
+ def self.minor: () -> Integer
6
+
7
+ def self.patch: () -> Integer
8
+
9
+ def self.pre: () -> Integer?
10
+
11
+ def self.to_h: () -> { major: Integer, minor: Integer, patch: Integer, pre: Integer? }
12
+
13
+ def self.to_a: () -> Array[Integer]
14
+
15
+ def self.to_s: () -> String
16
+ end
17
+ end
data/sig/bluepill.rbs CHANGED
@@ -15,23 +15,7 @@ module Bluepill
15
15
 
16
16
  # Loads an application from a config file. The block runs with self set to
17
17
  # the AppProxy, and also gets it as an argument.
18
- def self.application: (_ToS app_name, ?Hash[Symbol, untyped] options) { (AppProxy app) [self: AppProxy] -> void } -> void
19
-
20
- module Version
21
- def self.major: () -> Integer
22
-
23
- def self.minor: () -> Integer
24
-
25
- def self.patch: () -> Integer
26
-
27
- def self.pre: () -> Integer?
28
-
29
- def self.to_h: () -> { major: Integer, minor: Integer, patch: Integer, pre: Integer? }
30
-
31
- def self.to_a: () -> Array[Integer]
32
-
33
- def self.to_s: () -> String
34
- end
18
+ def self.application: (_ToS app_name, **untyped options) { (AppProxy app) [self: AppProxy] -> void } -> void
35
19
 
36
20
  # The monotonic clock that times ticks, checks and grace times
37
21
  module Clock
@@ -93,6 +77,9 @@ module Bluepill
93
77
  # does
94
78
  def self.underscore: (String name) -> String
95
79
 
80
+ # Logs an error at err, with a line for each backtrace line
81
+ def self.log_error: (Logger logger, String summary, Exception error) -> void
82
+
96
83
  # An array that drops its oldest element when it grows past its capacity
97
84
  class RotationalArray[Elem] < Array[Elem]
98
85
  @capacity: Integer
data/sig/manifest.yaml CHANGED
@@ -1,5 +1,6 @@
1
1
  # Standard libraries that bluepill's signatures use
2
2
  dependencies:
3
+ - name: etc
3
4
  - name: logger
4
5
  - name: monitor
5
6
  - name: net-http