Class: Homebrew::Service Private
- Extended by:
- Forwardable
- Includes:
- OnSystem::MacOSAndLinux
- Defined in:
- service.rb,
sorbet/rbi/dsl/homebrew/service.rbi
Overview
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
The Service class implements the DSL methods used in a formula's
service block and stores related instance variables. Most of these methods
also return the related instance variable when no argument is provided.
Constant Summary collapse
- RUN_TYPE_IMMEDIATE =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
:immediate- RUN_TYPE_INTERVAL =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
:interval- RUN_TYPE_CRON =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
:cron- PROCESS_TYPE_BACKGROUND =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
:background- PROCESS_TYPE_STANDARD =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
:standard- PROCESS_TYPE_INTERACTIVE =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
:interactive- PROCESS_TYPE_ADAPTIVE =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
:adaptive- KEEP_ALIVE_KEYS =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
[:always, :successful_exit, :crashed, :path].freeze
- NICE_RANGE =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
T.let(-20..19, T::Range[Integer])
- SOCKET_STRING_REGEX =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
%r{^(?<type>[a-z]+)://(?<host>.+):(?<port>[0-9]+)$}i- RunParam =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
T.type_alias { T.nilable(T.any(T::Array[T.any(String, Pathname)], String, Pathname)) }
- Sockets =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
T.type_alias { T::Hash[Symbol, { host: String, port: String, type: String }] }
Instance Attribute Summary collapse
- #plist_name ⇒ String readonly private
- #service_name ⇒ String readonly private
Class Method Summary collapse
-
.from_hash(api_hash) ⇒ Hash{Symbol => T.untyped}
private
Turn the service API hash values back into what is expected by the formula DSL.
-
.replace_placeholders(string) ⇒ String
private
Replace API path placeholders with local paths.
Instance Method Summary collapse
- #bin(*args, &block) ⇒ T.untyped private
- #command ⇒ Array<String> private
- #command? ⇒ Boolean private
- #cron(value = T.unsafe(nil)) ⇒ Hash{Symbol => Integer, String} private
- #default_cron_values ⇒ Hash{Symbol => Integer, String} private
- #default_plist_name ⇒ String private
- #default_service_name ⇒ String private
- #environment_variables(variables = {}) ⇒ Hash{Symbol => String}? private
- #error_log_path(path = T.unsafe(nil)) ⇒ String? private
- #etc(*args, &block) ⇒ T.untyped private
- #f ⇒ Formula private
- #initialize(formula, &block) ⇒ void constructor private
- #input_path(path = T.unsafe(nil)) ⇒ String? private
- #interval(value = T.unsafe(nil)) ⇒ Integer? private
- #keep_alive(value = T.unsafe(nil)) ⇒ Hash{Symbol => T.untyped}? private
-
#keep_alive? ⇒ Boolean
private
Returns a
Booleandescribing if a service is set to be kept alive. - #launch_only_once(value = T.unsafe(nil)) ⇒ Boolean private
- #libexec(*args, &block) ⇒ T.untyped private
- #log_path(path = T.unsafe(nil)) ⇒ String? private
- #macos_legacy_timers(value = T.unsafe(nil)) ⇒ Boolean private
-
#manual_command ⇒ String
private
Returns the
Stringcommand to run manually instead of the service. - #name(macos: nil, linux: nil) ⇒ void private
- #nice(value = T.unsafe(nil)) ⇒ Integer? private
- #nice_requires_root? ⇒ Boolean private
- #opt_bin(*args, &block) ⇒ T.untyped private
- #opt_libexec(*args, &block) ⇒ T.untyped private
- #opt_pkgshare(*args, &block) ⇒ T.untyped private
- #opt_prefix(*args, &block) ⇒ T.untyped private
- #opt_sbin(*args, &block) ⇒ T.untyped private
- #parse_cron(cron_statement) ⇒ Hash{Symbol => Integer, String} private
- #process_type(value = T.unsafe(nil)) ⇒ Symbol? private
- #require_root(value = T.unsafe(nil)) ⇒ Boolean private
-
#requires_root? ⇒ Boolean
private
Returns a
Booleandescribing if a service requires root access. - #restart_delay(value = T.unsafe(nil)) ⇒ Integer? private
- #root_dir(path = T.unsafe(nil)) ⇒ String? private
- #run(command = nil, macos: nil, linux: nil) ⇒ Array<String, Pathname>? private
- #run_at_load(value = T.unsafe(nil)) ⇒ Boolean? private
- #run_type(value = T.unsafe(nil)) ⇒ Symbol? private
- #sockets(value = T.unsafe(nil)) ⇒ Hash{Symbol => Hash{Symbol => String}} private
- #std_service_path_env ⇒ String private
- #throttle_interval(value = T.unsafe(nil)) ⇒ Integer? private
-
#timed? ⇒ Boolean
private
Returns a
Booleandescribing if a service is timed. -
#to_hash ⇒ Hash{Symbol => T.untyped}
private
Prepare the service hash for inclusion in the formula API JSON.
-
#to_plist ⇒ String
private
Returns a
Stringplist. -
#to_systemd_timer ⇒ String
private
Returns a
Stringsystemd unit timer. -
#to_systemd_unit ⇒ String
private
Returns a
Stringsystemd unit. - #var(*args, &block) ⇒ T.untyped private
- #working_dir(path = T.unsafe(nil)) ⇒ String? private
Methods included from OnSystem::MacOSAndLinux
included, #on_arch_conditional, #on_macos, #on_system_conditional
Constructor Details
#initialize(formula, &block) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'service.rb', line 36 def initialize(formula, &block) @cron = T.let({}, T::Hash[Symbol, T.any(Integer, String)]) @environment_variables = T.let({}, T::Hash[Symbol, String]) @error_log_path = T.let(nil, T.nilable(String)) @formula = formula @input_path = T.let(nil, T.nilable(String)) @interval = T.let(nil, T.nilable(Integer)) @keep_alive = T.let({}, T::Hash[Symbol, T.untyped]) @launch_only_once = T.let(false, T::Boolean) @log_path = T.let(nil, T.nilable(String)) @macos_legacy_timers = T.let(false, T::Boolean) @nice = T.let(nil, T.nilable(Integer)) @plist_name = T.let(default_plist_name, String) @process_type = T.let(nil, T.nilable(Symbol)) @require_root = T.let(false, T::Boolean) @restart_delay = T.let(nil, T.nilable(Integer)) @throttle_interval = T.let(nil, T.nilable(Integer)) @root_dir = T.let(nil, T.nilable(String)) @run = T.let([], T::Array[String]) @run_at_load = T.let(true, T::Boolean) @run_params = T.let(nil, T.any(RunParam, T::Hash[Symbol, RunParam])) @run_type = T.let(RUN_TYPE_IMMEDIATE, Symbol) @service_name = T.let(default_service_name, String) @sockets = T.let({}, Sockets) @working_dir = T.let(nil, T.nilable(String)) instance_eval(&block) if block raise TypeError, "Service#nice: require_root true is required for negative nice values" if nice_requires_root? end |
Instance Attribute Details
#plist_name ⇒ String (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
33 34 35 |
# File 'service.rb', line 33 def plist_name @plist_name end |
#service_name ⇒ String (readonly)
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
33 34 35 |
# File 'service.rb', line 33 def service_name @service_name end |
Class Method Details
.from_hash(api_hash) ⇒ Hash{Symbol => T.untyped}
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Turn the service API hash values back into what is expected by the formula DSL.
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 |
# File 'service.rb', line 598 def self.from_hash(api_hash) hash = {} hash[:name] = api_hash["name"].transform_keys(&:to_sym) if api_hash.key?("name") # The service hash might not have a "run" command if it only documents # an existing service file with the "name" command. return hash unless api_hash.key?("run") hash[:run] = case api_hash["run"] when String replace_placeholders(api_hash["run"]) when Array api_hash["run"].map { replace_placeholders(_1) } when Hash api_hash["run"].to_h do |key, elem| run_cmd = if elem.is_a?(Array) elem.map { replace_placeholders(_1) } else replace_placeholders(elem) end [key.to_sym, run_cmd] end else raise ArgumentError, "Unexpected run command: #{api_hash["run"]}" end if api_hash.key?("environment_variables") hash[:environment_variables] = api_hash["environment_variables"].to_h do |key, value| [key.to_sym, replace_placeholders(value)] end end %w[run_type process_type].each do |key| next unless (value = api_hash[key]) hash[key.to_sym] = value.to_sym end %w[working_dir root_dir input_path log_path error_log_path].each do |key| next unless (value = api_hash[key]) hash[key.to_sym] = replace_placeholders(value) end %w[interval cron launch_only_once require_root restart_delay throttle_interval nice macos_legacy_timers].each do |key| next if (value = api_hash[key]).nil? hash[key.to_sym] = value end %w[sockets keep_alive].each do |key| next unless (value = api_hash[key]) hash[key.to_sym] = if value.is_a?(Hash) value.transform_keys(&:to_sym) else value end end hash end |
.replace_placeholders(string) ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Replace API path placeholders with local paths.
666 667 668 669 670 |
# File 'service.rb', line 666 def self.replace_placeholders(string) string.gsub(HOMEBREW_PREFIX_PLACEHOLDER, HOMEBREW_PREFIX) .gsub(HOMEBREW_CELLAR_PLACEHOLDER, HOMEBREW_CELLAR) .gsub(HOMEBREW_HOME_PLACEHOLDER, Dir.home) end |
Instance Method Details
#bin(*args, &block) ⇒ T.untyped
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
10 |
# File 'sorbet/rbi/dsl/homebrew/service.rbi', line 10 def bin(*args, &block); end |
#command ⇒ Array<String>
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
388 389 390 |
# File 'service.rb', line 388 def command @run.map(&:to_s).map { |arg| arg.start_with?("~") ? File.(arg) : arg } end |
#command? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
393 394 395 |
# File 'service.rb', line 393 def command? !@run.empty? end |
#cron(value = T.unsafe(nil)) ⇒ Hash{Symbol => Integer, String}
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
303 304 305 306 307 308 309 |
# File 'service.rb', line 303 def cron(value = T.unsafe(nil)) if value @cron = parse_cron(value) else @cron end end |
#default_cron_values ⇒ Hash{Symbol => Integer, String}
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
312 313 314 315 316 317 318 319 320 |
# File 'service.rb', line 312 def default_cron_values { Month: "*", Day: "*", Weekday: "*", Hour: "*", Minute: "*", } end |
#default_plist_name ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
77 78 79 |
# File 'service.rb', line 77 def default_plist_name "homebrew.mxcl.#{@formula.name}" end |
#default_service_name ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
82 83 84 |
# File 'service.rb', line 82 def default_service_name "homebrew.#{@formula.name}" end |
#environment_variables(variables = {}) ⇒ Hash{Symbol => String}?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
358 359 360 |
# File 'service.rb', line 358 def environment_variables(variables = {}) @environment_variables = variables.transform_values(&:to_s) end |
#error_log_path(path = T.unsafe(nil)) ⇒ String?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
157 158 159 160 161 162 163 |
# File 'service.rb', line 157 def error_log_path(path = T.unsafe(nil)) if path @error_log_path = path.to_s else @error_log_path end end |
#etc(*args, &block) ⇒ T.untyped
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
13 |
# File 'sorbet/rbi/dsl/homebrew/service.rbi', line 13 def etc(*args, &block); end |
#f ⇒ Formula
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
72 73 74 |
# File 'service.rb', line 72 def f @formula end |
#input_path(path = T.unsafe(nil)) ⇒ String?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
139 140 141 142 143 144 145 |
# File 'service.rb', line 139 def input_path(path = T.unsafe(nil)) if path @input_path = path.to_s else @input_path end end |
#interval(value = T.unsafe(nil)) ⇒ Integer?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
294 295 296 297 298 299 300 |
# File 'service.rb', line 294 def interval(value = T.unsafe(nil)) if value @interval = value else @interval end end |
#keep_alive(value = T.unsafe(nil)) ⇒ Hash{Symbol => T.untyped}?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'service.rb', line 169 def keep_alive(value = T.unsafe(nil)) case value when nil @keep_alive when true, false @keep_alive = { always: value } when Hash unless (value.keys - KEEP_ALIVE_KEYS).empty? raise TypeError, "Service#keep_alive only allows: #{KEEP_ALIVE_KEYS}" end @keep_alive = value end end |
#keep_alive? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Returns a Boolean describing if a service is set to be kept alive.
238 239 240 |
# File 'service.rb', line 238 def keep_alive? !@keep_alive.empty? && @keep_alive[:always] != false end |
#launch_only_once(value = T.unsafe(nil)) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
243 244 245 246 247 248 249 |
# File 'service.rb', line 243 def launch_only_once(value = T.unsafe(nil)) if value.nil? @launch_only_once else @launch_only_once = value end end |
#libexec(*args, &block) ⇒ T.untyped
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
16 |
# File 'sorbet/rbi/dsl/homebrew/service.rbi', line 16 def libexec(*args, &block); end |
#log_path(path = T.unsafe(nil)) ⇒ String?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
148 149 150 151 152 153 154 |
# File 'service.rb', line 148 def log_path(path = T.unsafe(nil)) if path @log_path = path.to_s else @log_path end end |
#macos_legacy_timers(value = T.unsafe(nil)) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
363 364 365 366 367 368 369 |
# File 'service.rb', line 363 def macos_legacy_timers(value = T.unsafe(nil)) if value.nil? @macos_legacy_timers else @macos_legacy_timers = value end end |
#manual_command ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Returns the String command to run manually instead of the service.
399 400 401 402 403 404 405 |
# File 'service.rb', line 399 def manual_command vars = @environment_variables.except(:PATH) .map { |k, v| "#{k}=\"#{v}\"" } vars.concat(command.map { |arg| Utils::Shell.sh_quote(arg) }) vars.join(" ") end |
#name(macos: nil, linux: nil) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
87 88 89 90 91 92 |
# File 'service.rb', line 87 def name(macos: nil, linux: nil) raise TypeError, "Service#name expects at least one String" if [macos, linux].none?(String) @plist_name = macos if macos @service_name = linux if linux end |
#nice(value = T.unsafe(nil)) ⇒ Integer?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
372 373 374 375 376 377 378 |
# File 'service.rb', line 372 def nice(value = T.unsafe(nil)) return @nice if value.nil? raise TypeError, "Service#nice value should be in #{NICE_RANGE}" unless NICE_RANGE.cover?(value) @nice = value end |
#nice_requires_root? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
67 68 69 |
# File 'service.rb', line 67 def nice_requires_root? @nice&.negative? == true && !requires_root? end |
#opt_bin(*args, &block) ⇒ T.untyped
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
19 |
# File 'sorbet/rbi/dsl/homebrew/service.rbi', line 19 def opt_bin(*args, &block); end |
#opt_libexec(*args, &block) ⇒ T.untyped
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
22 |
# File 'sorbet/rbi/dsl/homebrew/service.rbi', line 22 def opt_libexec(*args, &block); end |
#opt_pkgshare(*args, &block) ⇒ T.untyped
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
25 |
# File 'sorbet/rbi/dsl/homebrew/service.rbi', line 25 def opt_pkgshare(*args, &block); end |
#opt_prefix(*args, &block) ⇒ T.untyped
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
28 |
# File 'sorbet/rbi/dsl/homebrew/service.rbi', line 28 def opt_prefix(*args, &block); end |
#opt_sbin(*args, &block) ⇒ T.untyped
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
31 |
# File 'sorbet/rbi/dsl/homebrew/service.rbi', line 31 def opt_sbin(*args, &block); end |
#parse_cron(cron_statement) ⇒ Hash{Symbol => Integer, String}
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
# File 'service.rb', line 323 def parse_cron(cron_statement) parsed = default_cron_values case cron_statement when "@hourly" parsed[:Minute] = 0 when "@daily" parsed[:Minute] = 0 parsed[:Hour] = 0 when "@weekly" parsed[:Minute] = 0 parsed[:Hour] = 0 parsed[:Weekday] = 0 when "@monthly" parsed[:Minute] = 0 parsed[:Hour] = 0 parsed[:Day] = 1 when "@yearly", "@annually" parsed[:Minute] = 0 parsed[:Hour] = 0 parsed[:Day] = 1 parsed[:Month] = 1 else cron_parts = cron_statement.split raise TypeError, "Service#parse_cron expects a valid cron syntax" if cron_parts.length != 5 [:Minute, :Hour, :Day, :Month, :Weekday].each_with_index do |selector, index| parsed[selector] = Integer(cron_parts.fetch(index)) if cron_parts.fetch(index) != "*" end end parsed end |
#process_type(value = T.unsafe(nil)) ⇒ Symbol?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'service.rb', line 268 def process_type(value = T.unsafe(nil)) case value when nil @process_type when :background, :standard, :interactive, :adaptive @process_type = value when Symbol raise TypeError, "Service#process_type allows: " \ "'#{PROCESS_TYPE_BACKGROUND}'/'#{PROCESS_TYPE_STANDARD}'/" \ "'#{PROCESS_TYPE_INTERACTIVE}'/'#{PROCESS_TYPE_ADAPTIVE}'" end end |
#require_root(value = T.unsafe(nil)) ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
185 186 187 188 189 190 191 |
# File 'service.rb', line 185 def require_root(value = T.unsafe(nil)) if value.nil? @require_root else @require_root = value end end |
#requires_root? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Returns a Boolean describing if a service requires root access.
195 196 197 |
# File 'service.rb', line 195 def requires_root? @require_root.present? && @require_root == true end |
#restart_delay(value = T.unsafe(nil)) ⇒ Integer?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
252 253 254 255 256 257 258 |
# File 'service.rb', line 252 def restart_delay(value = T.unsafe(nil)) if value @restart_delay = value else @restart_delay end end |
#root_dir(path = T.unsafe(nil)) ⇒ String?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
130 131 132 133 134 135 136 |
# File 'service.rb', line 130 def root_dir(path = T.unsafe(nil)) if path @root_dir = path.to_s else @root_dir end end |
#run(command = nil, macos: nil, linux: nil) ⇒ Array<String, Pathname>?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'service.rb', line 101 def run(command = nil, macos: nil, linux: nil) # Save parameters for serialization if command @run_params = command elsif macos || linux @run_params = { macos:, linux: }.compact end command ||= on_system_conditional(macos:, linux:) case command when nil @run when String, Pathname @run = [command.to_s] when Array @run = command.map(&:to_s) end end |
#run_at_load(value = T.unsafe(nil)) ⇒ Boolean?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
200 201 202 203 204 205 206 |
# File 'service.rb', line 200 def run_at_load(value = T.unsafe(nil)) if value.nil? @run_at_load else @run_at_load = value end end |
#run_type(value = T.unsafe(nil)) ⇒ Symbol?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
282 283 284 285 286 287 288 289 290 291 |
# File 'service.rb', line 282 def run_type(value = T.unsafe(nil)) case value when nil @run_type when :immediate, :interval, :cron @run_type = value when Symbol raise TypeError, "Service#run_type allows: '#{RUN_TYPE_IMMEDIATE}'/'#{RUN_TYPE_INTERVAL}'/'#{RUN_TYPE_CRON}'" end end |
#sockets(value = T.unsafe(nil)) ⇒ Hash{Symbol => Hash{Symbol => String}}
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'service.rb', line 212 def sockets(value = T.unsafe(nil)) return @sockets if value.nil? value_hash = case value when String { listeners: value } when Hash value end @sockets = T.must(value_hash).transform_values do |socket_string| match = socket_string.match(SOCKET_STRING_REGEX) raise TypeError, "Service#sockets a formatted socket definition as <type>://<host>:<port>" unless match begin IPAddr.new(match[:host]) rescue IPAddr::InvalidAddressError raise TypeError, "Service#sockets expects a valid ipv4 or ipv6 host address" end { host: match[:host], port: match[:port], type: match[:type] } end end |
#std_service_path_env ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
383 384 385 |
# File 'service.rb', line 383 def std_service_path_env "#{HOMEBREW_PREFIX}/bin:#{HOMEBREW_PREFIX}/sbin:/usr/bin:/bin:/usr/sbin:/sbin" end |
#throttle_interval(value = T.unsafe(nil)) ⇒ Integer?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
261 262 263 264 265 |
# File 'service.rb', line 261 def throttle_interval(value = T.unsafe(nil)) return @throttle_interval if value.nil? @throttle_interval = value end |
#timed? ⇒ Boolean
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Returns a Boolean describing if a service is timed.
409 410 411 |
# File 'service.rb', line 409 def timed? @run_type == RUN_TYPE_CRON || @run_type == RUN_TYPE_INTERVAL end |
#to_hash ⇒ Hash{Symbol => T.untyped}
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Prepare the service hash for inclusion in the formula API JSON.
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 |
# File 'service.rb', line 543 def to_hash name_params = { macos: (plist_name if plist_name != default_plist_name), linux: (service_name if service_name != default_service_name), }.compact return { name: name_params }.compact_blank if @run_params.blank? cron_string = if @cron.present? [:Minute, :Hour, :Day, :Month, :Weekday] .filter_map { |key| @cron[key].to_s.presence } .join(" ") end sockets_var = unless @sockets.empty? @sockets.transform_values { |info| "#{info[:type]}://#{info[:host]}:#{info[:port]}" } .then do |sockets_hash| # TODO: Remove this code when all users are running on versions of Homebrew # that can process sockets hashes (this commit or later). if sockets_hash.size == 1 && sockets_hash.key?(:listeners) # When original #sockets argument was a string: `sockets "tcp://127.0.0.1:80"` sockets_hash.fetch(:listeners) else # When original #sockets argument was a hash: `sockets http: "tcp://0.0.0.0:80"` sockets_hash end end end { name: name_params.presence, run: @run_params, run_type: @run_type, interval: @interval, cron: cron_string.presence, keep_alive: @keep_alive, launch_only_once: @launch_only_once, require_root: @require_root, environment_variables: @environment_variables.presence, working_dir: @working_dir, root_dir: @root_dir, input_path: @input_path, log_path: @log_path, error_log_path: @error_log_path, restart_delay: @restart_delay, throttle_interval: @throttle_interval, nice: @nice, process_type: @process_type, macos_legacy_timers: @macos_legacy_timers, sockets: sockets_var, }.compact_blank end |
#to_plist ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Returns a String plist.
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 |
# File 'service.rb', line 415 def to_plist # command needs to be first because it initializes all other values base = { Label: plist_name, ProgramArguments: command, RunAtLoad: @run_at_load == true, } base[:LaunchOnlyOnce] = @launch_only_once if @launch_only_once == true base[:LegacyTimers] = @macos_legacy_timers if @macos_legacy_timers == true base[:TimeOut] = @restart_delay if @restart_delay.present? base[:ThrottleInterval] = @throttle_interval if @throttle_interval.present? base[:ProcessType] = @process_type.to_s.capitalize if @process_type.present? base[:Nice] = @nice if @nice.present? base[:StartInterval] = @interval if @interval.present? && @run_type == RUN_TYPE_INTERVAL base[:WorkingDirectory] = File.(@working_dir) if @working_dir.present? base[:RootDirectory] = File.(@root_dir) if @root_dir.present? base[:StandardInPath] = File.(@input_path) if @input_path.present? base[:StandardOutPath] = File.(@log_path) if @log_path.present? base[:StandardErrorPath] = File.(@error_log_path) if @error_log_path.present? base[:EnvironmentVariables] = @environment_variables unless @environment_variables.empty? if keep_alive? if (always = @keep_alive[:always].presence) base[:KeepAlive] = always elsif @keep_alive.key?(:successful_exit) base[:KeepAlive] = { SuccessfulExit: @keep_alive[:successful_exit] } elsif @keep_alive.key?(:crashed) base[:KeepAlive] = { Crashed: @keep_alive[:crashed] } elsif @keep_alive.key?(:path) && @keep_alive[:path].present? base[:KeepAlive] = { PathState: @keep_alive[:path].to_s } end end unless @sockets.empty? base[:Sockets] = {} @sockets.each do |name, info| base[:Sockets][name] = { SockNodeName: info[:host], SockServiceName: info[:port], SockProtocol: info[:type].upcase, } end end if !@cron.empty? && @run_type == RUN_TYPE_CRON base[:StartCalendarInterval] = @cron.reject { |_, value| value == "*" } end # Adding all session types has as the primary effect that if you initialise it through e.g. a Background session # and you later "physically" sign in to the owning account (Aqua session), things shouldn't flip out. # Also, we're not checking @process_type here because that is used to indicate process priority and not # necessarily if it should run in a specific session type. Like database services could run with ProcessType # Interactive so they have no resource limitations enforced upon them, but they aren't really interactive in the # general sense. base[:LimitLoadToSessionType] = %w[Aqua Background LoginWindow StandardIO System] base.to_plist end |
#to_systemd_timer ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Returns a String systemd unit timer.
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 |
# File 'service.rb', line 517 def to_systemd_timer = [] << "Persistent=true" if @run_type == RUN_TYPE_CRON << "OnUnitActiveSec=#{@interval}" if @run_type == RUN_TYPE_INTERVAL if @run_type == RUN_TYPE_CRON minutes = (@cron[:Minute] == "*") ? "*" : format("%02d", @cron[:Minute]) hours = (@cron[:Hour] == "*") ? "*" : format("%02d", @cron[:Hour]) << "OnCalendar=#{@cron[:Weekday]}-*-#{@cron[:Month]}-#{@cron[:Day]} #{hours}:#{minutes}:00" end <<~SYSTEMD [Unit] Description=Homebrew generated timer for #{@formula.name} [Install] WantedBy=timers.target [Timer] Unit=#{service_name} #{.join("\n")} SYSTEMD end |
#to_systemd_unit ⇒ String
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
Returns a String systemd unit.
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 |
# File 'service.rb', line 477 def to_systemd_unit # command needs to be first because it initializes all other values cmd = command.map { |arg| Utils::Service.systemd_quote(arg) } .join(" ") = [] << "Type=#{(@launch_only_once == true) ? "oneshot" : "simple"}" << "ExecStart=#{cmd}" if @keep_alive.present? if @keep_alive[:always].present? || @keep_alive[:crashed].present? # Use on-failure instead of always to allow manual stops via systemctl << "Restart=on-failure" elsif @keep_alive[:successful_exit].present? << "Restart=on-success" end end << "RestartSec=#{restart_delay}" if @restart_delay.present? << "Nice=#{@nice}" if @nice.present? << "WorkingDirectory=#{File.(@working_dir)}" if @working_dir.present? << "RootDirectory=#{File.(@root_dir)}" if @root_dir.present? << "StandardInput=file:#{File.(@input_path)}" if @input_path.present? << "StandardOutput=append:#{File.(@log_path)}" if @log_path.present? << "StandardError=append:#{File.(@error_log_path)}" if @error_log_path.present? += @environment_variables.map { |k, v| "Environment=\"#{k}=#{v}\"" } if @environment_variables.present? <<~SYSTEMD [Unit] Description=Homebrew generated unit for #{@formula.name} [Install] WantedBy=default.target [Service] #{.join("\n")} SYSTEMD end |
#var(*args, &block) ⇒ T.untyped
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
34 |
# File 'sorbet/rbi/dsl/homebrew/service.rbi', line 34 def var(*args, &block); end |
#working_dir(path = T.unsafe(nil)) ⇒ String?
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
121 122 123 124 125 126 127 |
# File 'service.rb', line 121 def working_dir(path = T.unsafe(nil)) if path @working_dir = path.to_s else @working_dir end end |