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
@@ -4,7 +4,7 @@ module Bluepill
4
4
  # The version of bluepill
5
5
  #
6
6
  # @example
7
- # Bluepill::Version.to_s # => "0.2.7"
7
+ # Bluepill::Version.to_s # => "0.3.0"
8
8
  #
9
9
  # @api public
10
10
  module Version
@@ -16,33 +16,27 @@ module Bluepill
16
16
  # @return [Integer] the major version
17
17
  #
18
18
  # @api public
19
- def self.major
20
- 0
21
- end
19
+ def self.major = 0
22
20
 
23
21
  # Return the minor version
24
22
  #
25
23
  # @example
26
- # Bluepill::Version.minor # => 2
24
+ # Bluepill::Version.minor # => 3
27
25
  #
28
26
  # @return [Integer] the minor version
29
27
  #
30
28
  # @api public
31
- def self.minor
32
- 2
33
- end
29
+ def self.minor = 3
34
30
 
35
31
  # Return the patch version
36
32
  #
37
33
  # @example
38
- # Bluepill::Version.patch # => 7
34
+ # Bluepill::Version.patch # => 0
39
35
  #
40
36
  # @return [Integer] the patch version
41
37
  #
42
38
  # @api public
43
- def self.patch
44
- 7
45
- end
39
+ def self.patch = 0
46
40
 
47
41
  # Return the pre-release version
48
42
  #
@@ -58,7 +52,7 @@ module Bluepill
58
52
  # Return the version's parts by name
59
53
  #
60
54
  # @example
61
- # Bluepill::Version.to_h # => {major: 0, minor: 2, patch: 7, pre: nil}
55
+ # Bluepill::Version.to_h # => {major: 0, minor: 3, patch: 0, pre: nil}
62
56
  #
63
57
  # @return [Hash{Symbol => Integer, nil}] the major, minor, patch and
64
58
  # pre-release versions
@@ -76,25 +70,21 @@ module Bluepill
76
70
  # Return the version's parts, without a missing pre-release version
77
71
  #
78
72
  # @example
79
- # Bluepill::Version.to_a # => [0, 2, 7]
73
+ # Bluepill::Version.to_a # => [0, 3, 0]
80
74
  #
81
75
  # @return [Array<Integer>] the parts of the version
82
76
  #
83
77
  # @api public
84
- def self.to_a
85
- to_h.values.compact
86
- end
78
+ def self.to_a = to_h.values.compact
87
79
 
88
80
  # Return the version as a string
89
81
  #
90
82
  # @example
91
- # Bluepill::Version.to_s # => "0.2.7"
83
+ # Bluepill::Version.to_s # => "0.3.0"
92
84
  #
93
- # @return [String] the version, such as "0.2.7"
85
+ # @return [String] the version, such as "0.3.0"
94
86
  #
95
87
  # @api public
96
- def self.to_s
97
- to_a.join(".")
98
- end
88
+ def self.to_s = to_a.join(".")
99
89
  end
100
90
  end
data/lib/bluepill.rb CHANGED
@@ -36,6 +36,7 @@ require "bluepill/clock"
36
36
  require "bluepill/units"
37
37
  require "bluepill/util/inflections"
38
38
 
39
+ require "bluepill/errors"
39
40
  require "bluepill/dsl/process_proxy"
40
41
  require "bluepill/dsl/process_factory"
41
42
  require "bluepill/dsl/app_proxy"
@@ -19,11 +19,11 @@ module Bluepill
19
19
  attr_accessor pids_dir: String
20
20
  attr_accessor log_file: String?
21
21
 
22
- @foreground: bool?
23
- @log_level: (Symbol | String)?
22
+ @foreground: bool
23
+ @log_level: Symbol | String
24
24
  @mutex: Thread::Mutex
25
25
 
26
- def initialize: (String name, ?Hash[Symbol, untyped] options) -> void
26
+ def initialize: (String name, ?foreground: bool, ?log_file: String?, ?log_level: Symbol | String, ?base_dir: String?, ?kill_timeout: Integer) -> void
27
27
 
28
28
  def foreground?: () -> bool
29
29
 
@@ -45,12 +45,14 @@ module Bluepill
45
45
 
46
46
  def add_process: (Process process, ?_ToS? group_name) -> Array[Process]
47
47
 
48
- def version: () -> singleton(Version)
48
+ def version: () -> String
49
49
 
50
50
  # Ruby's protected methods are private in RBS
51
51
 
52
52
  private
53
53
 
54
+ def log_crash: (StandardError error) -> void
55
+
54
56
  def send_to_process_or_group: (Symbol method, String? group_name, String? process_name) -> Array[String]
55
57
 
56
58
  def send_to_groups: (Symbol method, *String args) -> Array[String]
@@ -108,7 +110,7 @@ module Bluepill
108
110
  def synchronize: [T] () { () -> T } -> T
109
111
  end
110
112
 
111
- @log_level: (Symbol | String)?
113
+ @log_level: Symbol | String
112
114
  @running: bool
113
115
 
114
116
  # Ruby's protected methods are private in RBS
@@ -119,8 +121,6 @@ module Bluepill
119
121
 
120
122
  def become_process_group_leader: () -> void
121
123
 
122
- def daemonize_and_trap_signals: () -> void
123
-
124
124
  def serve: () -> void
125
125
 
126
126
  def run: () -> void
@@ -129,10 +129,12 @@ module Bluepill
129
129
 
130
130
  def setup_signal_traps: () -> void
131
131
 
132
- def setup_logger_and_pids_dir: () -> void
132
+ def setup_logger: () -> void
133
133
 
134
134
  def setup_pids_dir: () -> void
135
135
 
136
+ def unwritable: (SystemCallError error) -> StartupError
137
+
136
138
  def write_pid_file: () -> void
137
139
  end
138
140
 
@@ -162,11 +164,14 @@ module Bluepill
162
164
  class Controller
163
165
  include Directory
164
166
 
167
+ TAIL_COMMAND: String
168
+ OUT_OF_DATE: String
169
+
165
170
  attr_accessor base_dir: String
166
171
  attr_accessor log_file: String?
167
172
  attr_reader base_directory: BaseDirectory
168
173
 
169
- def initialize: (Hash[Symbol, untyped] options) -> void
174
+ def initialize: (base_dir: String, ?log_file: String?) -> void
170
175
 
171
176
  def handle_command: (String application, String | Symbol command, *String args) -> void
172
177
 
@@ -185,8 +190,6 @@ module Bluepill
185
190
 
186
191
  def print_affected: (String | Symbol command, Array[String] affected) -> void
187
192
 
188
- def exit_with_daemon_error: (Exception error) -> void
189
-
190
193
  def verify_version!: (String application) -> void
191
194
 
192
195
  # Finds the daemons in the base directory, for Controller only
@@ -220,6 +223,8 @@ module Bluepill
220
223
 
221
224
  def pids_dir: () -> String
222
225
 
226
+ def journals_dir: () -> String
227
+
223
228
  def socket_file: (String app) -> String
224
229
 
225
230
  def pid_file: (String app) -> String
@@ -246,7 +251,7 @@ module Bluepill
246
251
  # Returns the daemon's response, unmarshaled
247
252
  def self.send_command: (String base_dir, String name, String command) -> untyped
248
253
 
249
- def self.retry_or_abort: (Integer current_attempt) -> void
254
+ def self.retry_or_give_up: (Integer current_attempt) -> void
250
255
 
251
256
  def self.server: (String base_dir, String name) -> UNIXServer
252
257
 
@@ -0,0 +1,48 @@
1
+ module Bluepill
2
+ # The options a config can set for a Process, and their defaults
3
+ module Process::Attributes
4
+ CONFIGURABLE_ATTRIBUTES: Array[Symbol]
5
+ APP_ATTRIBUTES: Array[Symbol]
6
+ CHILD_ATTRIBUTES: Array[Symbol]
7
+ NO_ENVIRONMENT: Hash[String, String]
8
+ DEFAULTS: Hash[Symbol, untyped]
9
+
10
+ attr_accessor pre_start_command: String?
11
+ attr_accessor start_command: String?
12
+ attr_accessor stop_command: String?
13
+ attr_accessor restart_command: String?
14
+ attr_accessor stdout: String?
15
+ attr_accessor stderr: String?
16
+ attr_accessor stdin: String?
17
+ attr_accessor daemonize: bool?
18
+ attr_accessor pid_file: String?
19
+ attr_accessor working_dir: String?
20
+ attr_accessor environment: Hash[_ToS, _ToS]?
21
+ attr_accessor start_grace_time: seconds
22
+ attr_accessor stop_grace_time: seconds
23
+ attr_accessor restart_grace_time: seconds
24
+ attr_accessor uid: String?
25
+ attr_accessor gid: String?
26
+ attr_accessor cache_actual_pid: bool
27
+ attr_accessor monitor_children: bool
28
+ attr_accessor child_process_factory: ProcessFactory::ChildFactory?
29
+ attr_accessor pid_command: String?
30
+ attr_accessor auto_start: bool?
31
+ attr_accessor supplementary_groups: Array[String]?
32
+ attr_reader stop_signals: Process::StopSignals?
33
+ # Takes signal names alternating with delays in seconds, too
34
+ def stop_signals=: (Process::StopSignals | Array[Symbol | Integer] | nil signals) -> Process::StopSignals?
35
+ attr_accessor on_start_timeout: Symbol
36
+ attr_accessor post_start_command: String?
37
+ attr_accessor pre_stop_command: String?
38
+ attr_accessor post_stop_command: String?
39
+ attr_accessor notify_command: String?
40
+ attr_accessor hook_timeout: seconds
41
+ attr_accessor group_start_noblock: bool
42
+ attr_accessor group_restart_noblock: bool
43
+ attr_accessor group_stop_noblock: bool
44
+ attr_accessor group_unmonitor_noblock: bool
45
+
46
+ def configure: (Hash[Symbol, untyped] options) -> void
47
+ end
48
+ end
@@ -1,17 +1,36 @@
1
1
  module Bluepill
2
+ # The checks and triggers a config can name, by their underscored class
3
+ # names
4
+ module CheckRegistry
5
+ # Each class, newest first, with the class it builds on and the methods
6
+ # it must define
7
+ self.@entries: Array[[Class, Class, Array[Symbol]]]
8
+
9
+ def self.add: (Class klass, Class base, Array[Symbol] required) -> void
10
+
11
+ def self.fetch: (Symbol | String name) -> Class
12
+
13
+ def self.names: () -> Array[String]
14
+
15
+ def self.check_name: (Class klass) -> String?
16
+
17
+ def self.missing_methods: (Class klass, Class base, Array[Symbol] required) -> Array[Symbol]
18
+
19
+ def self.unknown_message: (String name) -> String
20
+ end
21
+
2
22
  # Runs a process condition every so often, and fires its events when the
3
23
  # check fails often enough
4
24
  class ConditionWatch
5
25
  # A value the watch got, and whether it passed the check
6
26
  class HistoryValue < Struct[_ToS]
7
27
  attr_accessor value: _ToS
8
- attr_accessor critical: bool
28
+ attr_accessor passed: bool
9
29
 
10
- def self.new: (_ToS value, bool critical) -> HistoryValue
30
+ def self.new: (_ToS value, bool passed) -> HistoryValue
11
31
  end
12
32
 
13
33
  EMPTY_ARRAY: Array[Symbol]
14
- WATCH_KEYS: Array[Symbol]
15
34
 
16
35
  attr_reader logger: Logger
17
36
  attr_accessor name: Symbol
@@ -27,12 +46,11 @@ module Bluepill
27
46
  @process_condition: ProcessConditions::ProcessCondition[untyped]
28
47
  @last_ran_at: Integer?
29
48
 
30
- def initialize: (Symbol name, ?Hash[Symbol, untyped] options) -> void
49
+ def initialize: (Symbol name, ?logger: untyped, ?fires: untyped, ?every: untyped, ?times: untyped, ?include_children: bool, **untyped condition_options) -> void
31
50
 
32
- def create_condition: (Hash[Symbol, untyped] options) -> void
51
+ def events_to_fire: (Array[untyped] events) -> Array[Symbol]
33
52
 
34
- # Sets the logger of the watch and its condition
35
- def logger=: (Logger logger) -> void
53
+ def create_condition: (Hash[Symbol, untyped] options) -> void
36
54
 
37
55
  # Returns the events to fire
38
56
  def due?: (Integer tick_number) -> bool
@@ -52,19 +70,17 @@ module Bluepill
52
70
  class Trigger
53
71
  HALT: :halt
54
72
 
55
- self.@implementations: Hash[Symbol, singleton(Trigger)]
73
+ REQUIRED_METHODS: Array[Symbol]
56
74
 
57
- def self.inherited: (singleton(Trigger) klass) -> void
58
-
59
- def self.[]: %a{implicitly-returns-nil} (Symbol name) -> singleton(Trigger)
75
+ def self.inherited: (Class klass) -> void
60
76
 
61
77
  attr_accessor process: Process
62
- attr_accessor logger: Logger
78
+ attr_reader logger: Logger
63
79
  attr_reader scheduled_events: Array[[Symbol, Thread]]
64
80
 
65
81
  @reason: String
66
82
 
67
- def initialize: (Process process, ?Hash[Symbol, untyped] options) -> void
83
+ def initialize: (Process process, ?logger: untyped) -> void
68
84
 
69
85
  def reset!: () -> void
70
86
 
@@ -94,7 +110,7 @@ module Bluepill
94
110
  attr_accessor retry_in: Integer
95
111
  attr_reader timeline: Util::RotationalArray[Integer]
96
112
 
97
- def initialize: (Process process, ?Hash[Symbol, untyped] options) -> void
113
+ def initialize: (Process process, ?times: Integer, ?within: Integer, ?retry_in: Integer, **untyped options) -> void
98
114
 
99
115
  def notify: (_Transition transition) -> void
100
116
 
@@ -105,23 +121,22 @@ module Bluepill
105
121
  end
106
122
 
107
123
  module ProcessConditions
108
- def self.[]: (Symbol | String name) -> singleton(ProcessCondition)
109
-
110
124
  # Checks something about a process. V is the type of value that run
111
125
  # returns and check tests.
112
126
  class ProcessCondition[V]
113
- @options: Hash[Symbol, untyped]
127
+ REQUIRED_METHODS: Array[Symbol]
128
+
129
+ def self.inherited: (Class klass) -> void
114
130
 
115
131
  # The watch's logger
116
- attr_accessor logger: Logger?
132
+ attr_reader logger: Logger?
117
133
 
118
- def initialize: (?Hash[Symbol, untyped] options) -> void
134
+ def initialize: (?logger: Logger?) -> void
119
135
 
120
136
  def run: (Integer? pid, boolish include_children) -> V
121
137
 
122
138
  # Whether the value is fine
123
139
  def check?: (V value) -> bool
124
- def check: (V value) -> bool
125
140
 
126
141
  def format_value: (V value) -> V
127
142
  end
@@ -137,6 +152,8 @@ module Bluepill
137
152
  class BelowThreshold[V < Numeric] < ProcessCondition[V]
138
153
  @below: Numeric
139
154
 
155
+ def initialize: (below: Numeric, **untyped options) -> void
156
+
140
157
  def check?: (V value) -> bool
141
158
  end
142
159
 
@@ -149,6 +166,8 @@ module Bluepill
149
166
  class FileTime < BelowThreshold[Float]
150
167
  @filename: String
151
168
 
169
+ def initialize: (filename: String, below: Numeric, **untyped options) -> void
170
+
152
171
  def run: (Integer? pid, boolish include_children) -> (Float | StandardError | nil)
153
172
 
154
173
  def check?: (Float | StandardError | nil value) -> bool
@@ -160,6 +179,9 @@ module Bluepill
160
179
  @pattern: Regexp?
161
180
  @open_timeout: Integer
162
181
  @read_timeout: Integer
182
+ @verify_ssl: boolish
183
+
184
+ def initialize: (url: String, ?kind: Integer | String | Symbol | nil, ?pattern: Regexp?, ?timeout: untyped, ?open_timeout: untyped, ?read_timeout: untyped, ?verify_ssl: boolish, **untyped options) -> void
163
185
 
164
186
  def run: (Integer? pid, boolish include_children) -> (Net::HTTPResponse | StandardError)
165
187
 
@@ -170,21 +192,12 @@ module Bluepill
170
192
  def response_class: (untyped kind) -> Class
171
193
 
172
194
  def new_session: () -> Net::HTTP
173
-
174
- def hide_net_http_bug: [T] () { () -> T } -> T
175
195
  end
176
196
 
177
- # Memory usage in kilobytes
197
+ # Memory usage in bytes
178
198
  class MemUsage < BelowThreshold[Float]
179
- MB: Integer
180
- FORMAT_STR: String
181
- MB_LABEL: String
182
- KB_LABEL: String
183
-
184
199
  def run: (Integer? pid, boolish include_children) -> Float
185
200
 
186
- def check?: (Float value) -> bool
187
-
188
201
  def format_value: (Float value) -> String
189
202
  end
190
203
 
data/sig/bluepill/dsl.rbs CHANGED
@@ -1,43 +1,93 @@
1
1
  module Bluepill
2
+ # The parts the application and process blocks share
3
+ module DSL
4
+ # The attributes a pill file sets with `name = value`. The writers and
5
+ # readers are defined at load, and evaluate turns a call of an unknown
6
+ # one into a ConfigError.
7
+ module Attributes : _Owner
8
+ # What Attributes uses from the class that includes it
9
+ interface _Owner
10
+ def attribute_owner: () -> String
11
+
12
+ # The class, which extends ClassMethods
13
+ def class: () -> ClassMethods
14
+ end
15
+
16
+ def self.included: (Module base) -> void
17
+
18
+ # The attribute macro
19
+ module ClassMethods : Module
20
+ @attribute_names: Array[Symbol]
21
+
22
+ attr_reader attribute_names: Array[Symbol]
23
+
24
+ def attribute: (*Symbol names) -> void
25
+ end
26
+
27
+ @attributes: Hash[Symbol, untyped]
28
+
29
+ attr_reader attributes: Hash[Symbol, untyped]
30
+
31
+ def evaluate: () { (untyped proxy) [self: untyped] -> void } -> untyped
32
+
33
+ private
34
+
35
+ def unknown_attribute_message: (_ToS? name) -> String
36
+
37
+ def suggest: (String attribute) -> String?
38
+ end
39
+ end
40
+
2
41
  # self in an application block
3
42
  class AppProxy
4
- APP_ATTRIBUTES: Array[Symbol]
5
-
6
- attr_accessor working_dir: String?
7
- attr_accessor uid: String?
8
- attr_accessor gid: String?
9
- attr_accessor supplementary_groups: Array[String]?
10
- attr_accessor environment: Hash[_ToS, _ToS]?
11
- attr_accessor auto_start: bool?
12
- attr_accessor notify_command: String?
43
+ include DSL::Attributes
44
+ extend DSL::Attributes::ClassMethods
45
+
46
+ def working_dir: () -> String?
47
+ def working_dir=: (String? value) -> String?
48
+ def uid: () -> String?
49
+ def uid=: (String? value) -> String?
50
+ def gid: () -> String?
51
+ def gid=: (String? value) -> String?
52
+ def supplementary_groups: () -> Array[String]?
53
+ def supplementary_groups=: (Array[String]? value) -> Array[String]?
54
+ def environment: () -> Hash[_ToS, _ToS]?
55
+ def environment=: (Hash[_ToS, _ToS]? value) -> Hash[_ToS, _ToS]?
56
+ def auto_start: () -> bool?
57
+ def auto_start=: (bool? value) -> bool?
58
+ def notify_command: () -> String?
59
+ def notify_command=: (String? value) -> String?
60
+
13
61
  attr_reader app: Application
14
62
 
63
+ @name: String
15
64
  @registry: ProcessFactory::Registry
16
65
 
17
- def initialize: (_ToS app_name, Hash[Symbol, untyped] options) -> void
66
+ def initialize: (_ToS app_name, **untyped options) -> void
18
67
 
19
68
  # The block runs with self set to the ProcessProxy, and also gets it as
20
69
  # an argument
21
70
  def process: (String process_name) { (ProcessProxy process) [self: ProcessProxy] -> void } -> Array[Process]
71
+
72
+ def attribute_owner: () -> String
22
73
  end
23
74
 
24
75
  # Builds processes from a process block in the config
25
76
  class ProcessFactory
26
- include Children
27
-
77
+ @attributes: Hash[Symbol, untyped]
28
78
  @process_block: process_block
29
79
  @registry: Registry
30
80
 
31
- attr_reader attributes: Hash[Symbol, untyped]
32
-
33
81
  def initialize: (Hash[Symbol, untyped] attributes, process_block process_block, ?Registry registry) -> void
34
82
 
35
83
  # The process, and the group its block set
36
- def create_process: (String name, String pids_dir) -> [Process, untyped]
84
+ def create_process: (String name, String pids_dir, logger: Logger) -> [Process, untyped]
37
85
 
38
86
  private
39
87
 
40
- def assign_default_pid_file: (Hash[Symbol, untyped] attributes, String process_name, String pids_dir) -> String?
88
+ def default_pid_file: (String process_name, String pids_dir) -> String
89
+
90
+ def children_attributes: (ProcessProxy process) -> Hash[Symbol, untyped]
41
91
 
42
92
  def validate_process!: (ProcessProxy process) -> void
43
93
 
@@ -49,78 +99,71 @@ module Bluepill
49
99
 
50
100
  def validate_stop_signals!: (ProcessProxy process) -> void
51
101
 
52
- def validate_stop_signal_order!: (Array[Symbol | Integer] stop_signals) -> void
102
+ def validate_stop_grace_time!: (Process::StopSignals stop_signals, seconds? stop_grace_time) -> void
53
103
 
54
- def validate_stop_grace_time!: (Array[Symbol | Integer] stop_signals, Integer? stop_grace_time) -> void
104
+ def validate_on_start_timeout!: (ProcessProxy process) -> void
55
105
 
56
- def warn_unless_pid_known: (ProcessProxy process, String? default_pid_file) -> void
106
+ def warn_unless_pid_known: (ProcessProxy process, String default_pid_file) -> void
57
107
 
58
108
  def config_error!: (String message) -> bot
59
109
 
60
110
  # The process names and pid files an application's config has used
61
111
  class Registry
62
- @process_keys: Hash[Array[String?], nil]
63
- @pid_files: Hash[String, nil]
112
+ @process_keys: Set[[String?, String]]
113
+ @pid_files: Set[String]
64
114
 
65
115
  def initialize: () -> void
66
116
 
67
117
  def add_process?: (_ToS? group, _ToS name) -> bool
68
118
 
69
119
  def add_pid_file?: (String pid_file) -> bool
70
-
71
- private
72
-
73
- def add?: [K < Hash::_Key] (Hash[K, nil] keys, K key) -> bool
74
120
  end
75
121
 
76
- # Creates the processes of a process's children, for ProcessFactory,
77
- # which is the only class that includes it
78
- module Children
122
+ # Creates the processes of a process's children, and checks their
123
+ # block when it's made
124
+ class ChildFactory
79
125
  @attributes: Hash[Symbol, untyped]
80
- @process_block: process_block
126
+ @child_process_block: process_block
127
+
128
+ def initialize: (String parent_name, Hash[Symbol, untyped] parent_attributes, process_block child_process_block) -> void
81
129
 
82
130
  def create_child_process: (String name, Integer pid, Logger logger) -> Process
83
131
 
84
132
  private
85
133
 
86
- def inherited_attributes: () -> Hash[Symbol, untyped]
87
-
88
- def validate_child_process!: (ProcessProxy child) -> void
134
+ def validate!: (String parent_name) -> void
89
135
  end
90
136
  end
91
137
 
92
- # self in a process block. Any attribute can be set with `name = value`,
93
- # `name value` or `name!` (for true), and read back with `name`.
138
+ # self in a process block. Each attribute is set with `name = value`
139
+ # and read back with `name`. The writers and readers are defined at load,
140
+ # from Process::CONFIGURABLE_ATTRIBUTES, so they aren't listed here.
94
141
  class ProcessProxy
95
- attr_reader attributes: Hash[Symbol, untyped]
96
- attr_reader watches: Hash[Symbol, Hash[Symbol, untyped]]
97
- attr_reader name: String
142
+ include DSL::Attributes
143
+ extend DSL::Attributes::ClassMethods
98
144
 
99
- def initialize: (String process_name, Hash[Symbol, untyped] attributes, process_block process_block) -> void
100
-
101
- # Sets or reads an attribute
102
- def method_missing: (Symbol name, *untyped args) -> untyped
145
+ attr_reader name: String
146
+ attr_reader child_process_block: process_block?
147
+ attr_reader actual_pid: Integer?
103
148
 
104
- def respond_to_missing?: (Symbol name, bool? include_private) -> bool
149
+ # The checks the block added, in order, with their options
150
+ @checks: Array[[Symbol, Hash[Symbol, untyped]]]
105
151
 
106
- # Whether a config can set the attribute on a process
107
- def self.attribute?: (Symbol name) -> bool
152
+ def initialize: (String process_name, Hash[Symbol, untyped] attributes, process_block process_block, ?actual_pid: Integer?) -> void
108
153
 
109
- def self.attribute_names: () -> Array[Symbol]
154
+ # The readers of the attributes the factory uses
155
+ def group: () -> untyped
156
+ def pid_file: () -> String?
157
+ def stop_command: () -> String?
158
+ def on_start_timeout: () -> untyped
110
159
 
111
- def checks: (Symbol name, ?Hash[Symbol, untyped] options) -> Hash[Symbol, untyped]
160
+ def checks: (Symbol name, **untyped options) -> nil
112
161
 
113
162
  # The block configures the children like a process block
114
- def monitor_children: () ?{ (ProcessProxy child) [self: ProcessProxy] -> void } -> process_block?
115
-
116
- def to_process: () -> Process
117
-
118
- private
119
-
120
- def attribute_call: (Symbol name, Array[untyped] args) -> ([Symbol, bool] | [Symbol, bool, untyped])?
163
+ def monitor_children: () ?{ (ProcessProxy child) [self: ProcessProxy] -> void } -> process_block
121
164
 
122
- def unknown_attribute!: (Symbol key) -> bot
165
+ def to_process: (**untyped options) -> Process
123
166
 
124
- def suggest: (Symbol key) -> String?
167
+ def attribute_owner: () -> String
125
168
  end
126
169
  end
@@ -0,0 +1,48 @@
1
+ module Bluepill
2
+ # An error that stops the bluepill command, with the status it exits with
3
+ class Error < StandardError
4
+ def exit_status: () -> Integer
5
+ end
6
+
7
+ # A mistake in a pill file
8
+ class ConfigError < Error
9
+ LIBRARY_DIR: String
10
+
11
+ def location: () -> String?
12
+
13
+ private
14
+
15
+ def outside_library?: (Thread::Backtrace::Location frame) -> bool
16
+ end
17
+
18
+ # The daemon couldn't start
19
+ class StartupError < Error
20
+ end
21
+
22
+ # A previous daemon for the application couldn't be stopped
23
+ class PreviousDaemonError < Error
24
+ end
25
+
26
+ # A daemon for the application is already running
27
+ class AlreadyRunningError < Error
28
+ end
29
+
30
+ # The CLI couldn't reach the daemon
31
+ class ConnectionError < Error
32
+ end
33
+
34
+ # The daemon runs another version of bluepill
35
+ class VersionMismatchError < Error
36
+ end
37
+
38
+ # The CLI was given a command it doesn't know
39
+ class UnknownCommandError < Error
40
+ end
41
+
42
+ # The daemon answered a command with an error
43
+ class DaemonError < Error
44
+ attr_reader daemon_error: Exception
45
+
46
+ def initialize: (Exception daemon_error) -> void
47
+ end
48
+ end