bluepill 0.2.9 → 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 (93) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +100 -2
  3. data/README.md +12 -7
  4. data/bin/bluepill +8 -2
  5. data/bluepill.gemspec +1 -1
  6. data/lib/bluepill/application/lifecycle.rb +44 -34
  7. data/lib/bluepill/application/listener.rb +1 -1
  8. data/lib/bluepill/application/previous_daemon.rb +12 -14
  9. data/lib/bluepill/application.rb +33 -29
  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 +45 -54
  14. data/lib/bluepill/controller/directory.rb +1 -3
  15. data/lib/bluepill/controller.rb +32 -37
  16. data/lib/bluepill/dsl/app_proxy.rb +68 -64
  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 +83 -84
  21. data/lib/bluepill/dsl/process_proxy.rb +61 -168
  22. data/lib/bluepill/dsl.rb +16 -15
  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 -16
  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 +55 -52
  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 -67
  46. data/lib/bluepill/process_conditions/mem_usage.rb +7 -45
  47. data/lib/bluepill/process_conditions/process_condition.rb +29 -47
  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 +18 -69
  70. data/lib/bluepill/triggers/flapping.rb +12 -8
  71. data/lib/bluepill/units.rb +7 -21
  72. data/lib/bluepill/version.rb +12 -22
  73. data/lib/bluepill.rb +1 -1
  74. data/sig/bluepill/application.rbs +11 -12
  75. data/sig/bluepill/attributes.rbs +48 -0
  76. data/sig/bluepill/checks.rbs +40 -40
  77. data/sig/bluepill/dsl.rbs +97 -60
  78. data/sig/bluepill/errors.rbs +48 -0
  79. data/sig/bluepill/logger.rbs +15 -31
  80. data/sig/bluepill/process.rbs +39 -305
  81. data/sig/bluepill/process_commands.rbs +235 -0
  82. data/sig/bluepill/stop_signals.rbs +21 -0
  83. data/sig/bluepill/system.rbs +154 -99
  84. data/sig/bluepill/version.rbs +17 -0
  85. data/sig/bluepill.rbs +1 -17
  86. data/sig/manifest.yaml +1 -0
  87. metadata +21 -8
  88. data/lib/bluepill/deprecation/custom_checks.rb +0 -193
  89. data/lib/bluepill/deprecation/dsl.rb +0 -141
  90. data/lib/bluepill/deprecation/options.rb +0 -140
  91. data/lib/bluepill/deprecation.rb +0 -92
  92. data/lib/bluepill/dsl/process_factory/children.rb +0 -99
  93. data/sig/bluepill/deprecation.rbs +0 -87
@@ -4,7 +4,7 @@ module Bluepill
4
4
  # The version of bluepill
5
5
  #
6
6
  # @example
7
- # Bluepill::Version.to_s # => "0.2.9"
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 # => 9
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
- 9
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: 9, 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, 9]
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.9"
83
+ # Bluepill::Version.to_s # => "0.3.0"
92
84
  #
93
- # @return [String] the version, such as "0.2.9"
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
@@ -33,10 +33,10 @@ require "timeout"
33
33
  require "logger"
34
34
 
35
35
  require "bluepill/clock"
36
- require "bluepill/deprecation"
37
36
  require "bluepill/units"
38
37
  require "bluepill/util/inflections"
39
38
 
39
+ require "bluepill/errors"
40
40
  require "bluepill/dsl/process_proxy"
41
41
  require "bluepill/dsl/process_factory"
42
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
 
@@ -51,7 +51,6 @@ module Bluepill
51
51
 
52
52
  private
53
53
 
54
- # Logs an error that stopped the daemon at crit, with its backtrace
55
54
  def log_crash: (StandardError error) -> void
56
55
 
57
56
  def send_to_process_or_group: (Symbol method, String? group_name, String? process_name) -> Array[String]
@@ -111,7 +110,7 @@ module Bluepill
111
110
  def synchronize: [T] () { () -> T } -> T
112
111
  end
113
112
 
114
- @log_level: (Symbol | String)?
113
+ @log_level: Symbol | String
115
114
  @running: bool
116
115
 
117
116
  # Ruby's protected methods are private in RBS
@@ -122,8 +121,6 @@ module Bluepill
122
121
 
123
122
  def become_process_group_leader: () -> void
124
123
 
125
- def daemonize_and_trap_signals: () -> void
126
-
127
124
  def serve: () -> void
128
125
 
129
126
  def run: () -> void
@@ -132,10 +129,12 @@ module Bluepill
132
129
 
133
130
  def setup_signal_traps: () -> void
134
131
 
135
- def setup_logger_and_pids_dir: () -> void
132
+ def setup_logger: () -> void
136
133
 
137
134
  def setup_pids_dir: () -> void
138
135
 
136
+ def unwritable: (SystemCallError error) -> StartupError
137
+
139
138
  def write_pid_file: () -> void
140
139
  end
141
140
 
@@ -172,7 +171,7 @@ module Bluepill
172
171
  attr_accessor log_file: String?
173
172
  attr_reader base_directory: BaseDirectory
174
173
 
175
- def initialize: (Hash[Symbol, untyped] options) -> void
174
+ def initialize: (base_dir: String, ?log_file: String?) -> void
176
175
 
177
176
  def handle_command: (String application, String | Symbol command, *String args) -> void
178
177
 
@@ -191,8 +190,6 @@ module Bluepill
191
190
 
192
191
  def print_affected: (String | Symbol command, Array[String] affected) -> void
193
192
 
194
- def exit_with_daemon_error: (Exception error) -> void
195
-
196
193
  def verify_version!: (String application) -> void
197
194
 
198
195
  # Finds the daemons in the base directory, for Controller only
@@ -226,6 +223,8 @@ module Bluepill
226
223
 
227
224
  def pids_dir: () -> String
228
225
 
226
+ def journals_dir: () -> String
227
+
229
228
  def socket_file: (String app) -> String
230
229
 
231
230
  def pid_file: (String app) -> String
@@ -252,7 +251,7 @@ module Bluepill
252
251
  # Returns the daemon's response, unmarshaled
253
252
  def self.send_command: (String base_dir, String name, String command) -> untyped
254
253
 
255
- def self.retry_or_abort: (Integer current_attempt) -> void
254
+ def self.retry_or_give_up: (Integer current_attempt) -> void
256
255
 
257
256
  def self.server: (String base_dir, String name) -> UNIXServer
258
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,25 +70,17 @@ module Bluepill
52
70
  class Trigger
53
71
  HALT: :halt
54
72
 
55
- self.@implementations: Hash[Symbol, singleton(Trigger)]
56
-
57
- def self.inherited: (singleton(Trigger) klass) -> void
58
-
59
- def self.[]: %a{implicitly-returns-nil} (Symbol name) -> singleton(Trigger)
73
+ REQUIRED_METHODS: Array[Symbol]
60
74
 
61
- # Makes a trigger, and warns about what 0.3.0 rejects in its class
62
- def self.create: (Process process, Symbol check_name, logger: Logger?, **untyped options) -> Trigger
75
+ def self.inherited: (Class klass) -> void
63
76
 
64
77
  attr_accessor process: Process
65
78
  attr_reader logger: Logger
66
-
67
- # Sets the logger, and warns when code outside bluepill calls it
68
- def logger=: (Logger logger) -> void
69
79
  attr_reader scheduled_events: Array[[Symbol, Thread]]
70
80
 
71
81
  @reason: String
72
82
 
73
- def initialize: (Process process, ?Hash[Symbol, untyped] options) -> void
83
+ def initialize: (Process process, ?logger: untyped) -> void
74
84
 
75
85
  def reset!: () -> void
76
86
 
@@ -100,7 +110,7 @@ module Bluepill
100
110
  attr_accessor retry_in: Integer
101
111
  attr_reader timeline: Util::RotationalArray[Integer]
102
112
 
103
- def initialize: (Process process, ?Hash[Symbol, untyped] options) -> void
113
+ def initialize: (Process process, ?times: Integer, ?within: Integer, ?retry_in: Integer, **untyped options) -> void
104
114
 
105
115
  def notify: (_Transition transition) -> void
106
116
 
@@ -111,26 +121,22 @@ module Bluepill
111
121
  end
112
122
 
113
123
  module ProcessConditions
114
- def self.[]: (Symbol | String name) -> singleton(ProcessCondition)
115
-
116
124
  # Checks something about a process. V is the type of value that run
117
125
  # returns and check tests.
118
126
  class ProcessCondition[V]
119
- @options: Hash[Symbol, untyped]
127
+ REQUIRED_METHODS: Array[Symbol]
128
+
129
+ def self.inherited: (Class klass) -> void
120
130
 
121
131
  # The watch's logger
122
132
  attr_reader logger: Logger?
123
133
 
124
- # Sets the logger, and warns when code outside bluepill calls it
125
- def logger=: (Logger? logger) -> void
126
-
127
- def initialize: (?Hash[Symbol, untyped] options) -> void
134
+ def initialize: (?logger: Logger?) -> void
128
135
 
129
136
  def run: (Integer? pid, boolish include_children) -> V
130
137
 
131
138
  # Whether the value is fine
132
139
  def check?: (V value) -> bool
133
- def check: (V value) -> bool
134
140
 
135
141
  def format_value: (V value) -> V
136
142
  end
@@ -146,6 +152,8 @@ module Bluepill
146
152
  class BelowThreshold[V < Numeric] < ProcessCondition[V]
147
153
  @below: Numeric
148
154
 
155
+ def initialize: (below: Numeric, **untyped options) -> void
156
+
149
157
  def check?: (V value) -> bool
150
158
  end
151
159
 
@@ -158,6 +166,8 @@ module Bluepill
158
166
  class FileTime < BelowThreshold[Float]
159
167
  @filename: String
160
168
 
169
+ def initialize: (filename: String, below: Numeric, **untyped options) -> void
170
+
161
171
  def run: (Integer? pid, boolish include_children) -> (Float | StandardError | nil)
162
172
 
163
173
  def check?: (Float | StandardError | nil value) -> bool
@@ -171,33 +181,23 @@ module Bluepill
171
181
  @read_timeout: Integer
172
182
  @verify_ssl: boolish
173
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
185
+
174
186
  def run: (Integer? pid, boolish include_children) -> (Net::HTTPResponse | StandardError)
175
187
 
176
188
  def check?: (Net::HTTPResponse | StandardError value) -> bool
177
189
 
178
190
  private
179
191
 
180
- # Warns about an https check that doesn't set verify_ssl
181
- def warn_unverified: (Hash[Symbol, untyped] options) -> void
182
-
183
192
  def response_class: (untyped kind) -> Class
184
193
 
185
194
  def new_session: () -> Net::HTTP
186
-
187
- def hide_net_http_bug: [T] () { () -> T } -> T
188
195
  end
189
196
 
190
- # Memory usage in kilobytes
197
+ # Memory usage in bytes
191
198
  class MemUsage < BelowThreshold[Float]
192
- MB: Integer
193
- FORMAT_STR: String
194
- MB_LABEL: String
195
- KB_LABEL: String
196
-
197
199
  def run: (Integer? pid, boolish include_children) -> Float
198
200
 
199
- def check?: (Float value) -> bool
200
-
201
201
  def format_value: (Float value) -> String
202
202
  end
203
203
 
data/sig/bluepill/dsl.rbs CHANGED
@@ -1,46 +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
- NO_OPTIONS: Hash[Symbol, untyped]
6
-
7
- attr_accessor working_dir: String?
8
- attr_accessor uid: String?
9
- attr_accessor gid: String?
10
- attr_accessor supplementary_groups: Array[String]?
11
- attr_accessor environment: Hash[_ToS, _ToS]?
12
- attr_accessor auto_start: bool?
13
- 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
+
14
61
  attr_reader app: Application
15
62
 
63
+ @name: String
16
64
  @registry: ProcessFactory::Registry
17
65
 
18
- def initialize: (_ToS app_name, ?Hash[Symbol, untyped] options) -> void
66
+ def initialize: (_ToS app_name, **untyped options) -> void
19
67
 
20
68
  # The block runs with self set to the ProcessProxy, and also gets it as
21
69
  # an argument
22
70
  def process: (String process_name) { (ProcessProxy process) [self: ProcessProxy] -> void } -> Array[Process]
71
+
72
+ def attribute_owner: () -> String
23
73
  end
24
74
 
25
75
  # Builds processes from a process block in the config
26
76
  class ProcessFactory
27
- include Children
28
-
77
+ @attributes: Hash[Symbol, untyped]
29
78
  @process_block: process_block
30
79
  @registry: Registry
31
80
 
32
- attr_reader attributes: Hash[Symbol, untyped]
33
-
34
81
  def initialize: (Hash[Symbol, untyped] attributes, process_block process_block, ?Registry registry) -> void
35
82
 
36
83
  # The process, and the group its block set
37
- def create_process: (String name, String pids_dir) -> [Process, untyped]
84
+ def create_process: (String name, String pids_dir, logger: Logger) -> [Process, untyped]
38
85
 
39
86
  private
40
87
 
41
- def child_factory: (String name, Hash[Symbol, untyped] attributes, process_block child_process_block) -> ProcessFactory
88
+ def default_pid_file: (String process_name, String pids_dir) -> String
42
89
 
43
- def assign_default_pid_file: (Hash[Symbol, untyped] attributes, String process_name, String pids_dir) -> String?
90
+ def children_attributes: (ProcessProxy process) -> Hash[Symbol, untyped]
44
91
 
45
92
  def validate_process!: (ProcessProxy process) -> void
46
93
 
@@ -52,81 +99,71 @@ module Bluepill
52
99
 
53
100
  def validate_stop_signals!: (ProcessProxy process) -> void
54
101
 
55
- 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
56
103
 
57
- def validate_stop_grace_time!: (Array[Symbol | Integer] stop_signals, Integer? stop_grace_time) -> void
104
+ def validate_on_start_timeout!: (ProcessProxy process) -> void
58
105
 
59
- 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
60
107
 
61
108
  def config_error!: (String message) -> bot
62
109
 
63
110
  # The process names and pid files an application's config has used
64
111
  class Registry
65
- @process_keys: Hash[Array[String?], nil]
66
- @pid_files: Hash[String, nil]
112
+ @process_keys: Set[[String?, String]]
113
+ @pid_files: Set[String]
67
114
 
68
115
  def initialize: () -> void
69
116
 
70
117
  def add_process?: (_ToS? group, _ToS name) -> bool
71
118
 
72
119
  def add_pid_file?: (String pid_file) -> bool
73
-
74
- private
75
-
76
- def add?: [K < Hash::_Key] (Hash[K, nil] keys, K key) -> bool
77
120
  end
78
121
 
79
- # Creates the processes of a process's children, for ProcessFactory,
80
- # which is the only class that includes it
81
- module Children
122
+ # Creates the processes of a process's children, and checks their
123
+ # block when it's made
124
+ class ChildFactory
82
125
  @attributes: Hash[Symbol, untyped]
83
- @process_block: process_block
126
+ @child_process_block: process_block
84
127
 
85
- def create_child_process: (String name, Integer pid, Logger logger) -> Process
128
+ def initialize: (String parent_name, Hash[Symbol, untyped] parent_attributes, process_block child_process_block) -> void
86
129
 
87
- # Warns about what 0.3.0 rejects in the children's block
88
- def check_children: (String parent_name) -> void
130
+ def create_child_process: (String name, Integer pid, Logger logger) -> Process
89
131
 
90
132
  private
91
133
 
92
- def inherited_attributes: () -> Hash[Symbol, untyped]
93
-
94
- def validate_child_process!: (ProcessProxy child) -> void
134
+ def validate!: (String parent_name) -> void
95
135
  end
96
136
  end
97
137
 
98
- # self in a process block. Any attribute can be set with `name = value`,
99
- # `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.
100
141
  class ProcessProxy
101
- attr_reader attributes: Hash[Symbol, untyped]
102
- attr_reader watches: Hash[Symbol, Hash[Symbol, untyped]]
103
- attr_reader name: String
142
+ include DSL::Attributes
143
+ extend DSL::Attributes::ClassMethods
104
144
 
105
- def initialize: (String process_name, Hash[Symbol, untyped] attributes, process_block process_block) -> void
106
-
107
- # Sets or reads an attribute
108
- 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?
109
148
 
110
- 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]]]
111
151
 
112
- # Whether a config can set the attribute on a process
113
- def self.attribute?: (Symbol name) -> bool
152
+ def initialize: (String process_name, Hash[Symbol, untyped] attributes, process_block process_block, ?actual_pid: Integer?) -> void
114
153
 
115
- 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
116
159
 
117
- def checks: (Symbol name, ?Hash[Symbol, untyped]? options, **untyped keywords) -> Hash[Symbol, untyped]
160
+ def checks: (Symbol name, **untyped options) -> nil
118
161
 
119
162
  # The block configures the children like a process block
120
- def monitor_children: () ?{ (ProcessProxy child) [self: ProcessProxy] -> void } -> process_block?
121
-
122
- def to_process: () -> Process
123
-
124
- private
125
-
126
- def attribute_call: (Symbol name, Array[untyped] args) -> ([Symbol, bool] | [Symbol, bool, untyped])?
163
+ def monitor_children: () ?{ (ProcessProxy child) [self: ProcessProxy] -> void } -> process_block
127
164
 
128
- def unknown_attribute!: (Symbol key) -> bot
165
+ def to_process: (**untyped options) -> Process
129
166
 
130
- def suggest: (Symbol key) -> String?
167
+ def attribute_owner: () -> String
131
168
  end
132
169
  end