Class: Homebrew::Bundle::Brew::Services Private
- Inherits:
-
Homebrew::Bundle::Brew
- Object
- PackageType
- Homebrew::Bundle::Brew
- Homebrew::Bundle::Brew::Services
- Extended by:
- Utils::Output::Mixin
- Defined in:
- bundle/brew_services.rb
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.
Constant Summary
Constants inherited from Homebrew::Bundle::Brew
PACKAGE_TYPE, PACKAGE_TYPE_NAME
Class Method Summary collapse
- .reset! ⇒ void private
- .restart(name, file: nil, verbose: false) ⇒ Boolean private
- .run(name, file: nil, verbose: false) ⇒ Boolean private
- .start(name, file: nil, verbose: false) ⇒ Boolean private
- .started?(name) ⇒ Boolean private
- .started_services ⇒ Array<String> private
- .stop(name, keep: false, verbose: false) ⇒ Object private
- .versioned_service_file(name) ⇒ Pathname? private
Instance Method Summary collapse
- #entry_to_formula(entry) ⇒ Homebrew::Bundle::Brew private
- #failure_reason(name, no_upgrade:) ⇒ String private
- #format_checkable(entries) ⇒ Array<Object> private
- #formula_needs_to_start?(formula) ⇒ Boolean private
- #installed_and_up_to_date?(formula, no_upgrade: false) ⇒ Boolean private
- #lookup_old_name(service_name) ⇒ String? private
Methods included from Utils::Output::Mixin
odebug, odeprecated, odie, odisabled, ofail, oh1, oh1_title, ohai, ohai_title, onoe, opoo, opoo_outside_github_actions, pretty_deprecated, pretty_disabled, pretty_duration, pretty_installed, pretty_outdated, pretty_uninstalled
Methods inherited from Homebrew::Bundle::Brew
#changed?, dump, dump_output, fetchable_name, formula_aliases, formula_in_array?, formula_installed?, formula_installed_and_up_to_date?, formula_oldnames, formula_upgradable?, formulae, formulae_by_full_name, formulae_by_name, inherited, #initialize, install!, #install!, #install_change_state!, install_verb, installed_formulae, #link_change_state!, no_upgrade_with_args?, outdated_formulae, pinned_formulae, #postinstall_change_state!, preinstall!, #preinstall!, #restart_service?, #restart_service_needed?, #service_change_state!, #start_service?, #start_service_needed?, upgradable_formulae
Methods inherited from PackageType
check, #checkable_entries, dump, dump_output, dump_supported?, #exit_early_check, fetchable_name, #find_actionable, #full_check, inherited, install!, install_supported?, install_verb, preinstall!, type
Constructor Details
This class inherits a constructor from Homebrew::Bundle::Brew
Class Method Details
.reset! ⇒ 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.
17 18 19 |
# File 'bundle/brew_services.rb', line 17 def reset! @started_services = nil end |
.restart(name, file: nil, verbose: false) ⇒ 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.
56 57 58 59 60 61 62 63 |
# File 'bundle/brew_services.rb', line 56 def restart(name, file: nil, verbose: false) args = ["services", "restart", name] args << "--file=#{file}" if file return false unless Bundle.brew(*args, verbose:) started_services << name true end |
.run(name, file: nil, verbose: false) ⇒ 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.
46 47 48 49 50 51 52 53 |
# File 'bundle/brew_services.rb', line 46 def run(name, file: nil, verbose: false) args = ["services", "run", name] args << "--file=#{file}" if file return false unless Bundle.brew(*args, verbose:) started_services << name true end |
.start(name, file: nil, verbose: false) ⇒ 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.
36 37 38 39 40 41 42 43 |
# File 'bundle/brew_services.rb', line 36 def start(name, file: nil, verbose: false) args = ["services", "start", name] args << "--file=#{file}" if file return false unless Bundle.brew(*args, verbose:) started_services << name true end |
.started?(name) ⇒ 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 'bundle/brew_services.rb', line 67 def started?(name) started_services.include? name end |
.started_services ⇒ 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.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'bundle/brew_services.rb', line 72 def started_services @started_services ||= T.let( begin if !Homebrew::Services::System.launchctl? && !Homebrew::Services::System.systemctl? odie Homebrew::Services::System::MISSING_DAEMON_MANAGER_EXCEPTION_MESSAGE end states_to_skip = %w[stopped none] services_list = JSON.parse(Utils.safe_popen_read(HOMEBREW_BREW_FILE, "services", "list", "--json")) services_list.filter_map do |hash| hash.fetch("name") if states_to_skip.exclude?(hash.fetch("status")) end end, T.nilable(T::Array[String]), ) end |
.stop(name, keep: false, verbose: false) ⇒ Object
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.
24 25 26 27 28 29 30 31 32 33 |
# File 'bundle/brew_services.rb', line 24 def stop(name, keep: false, verbose: false) return true unless started?(name) args = ["services", "stop", name] args << "--keep" if keep return false unless Bundle.brew(*args, verbose:) started_services.delete(name) true end |
.versioned_service_file(name) ⇒ 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.
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'bundle/brew_services.rb', line 90 def versioned_service_file(name) env_version = Bundle.formula_versions_from_env(name) return if env_version.nil? formula = Formula[name] prefix = formula.rack/env_version return unless prefix.directory? service_file = if Homebrew::Services::System.launchctl? prefix/"#{formula.plist_name}.plist" else prefix/"#{formula.service_name}.service" end service_file if service_file.file? end |
Instance Method Details
#entry_to_formula(entry) ⇒ Homebrew::Bundle::Brew
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.
137 138 139 |
# File 'bundle/brew_services.rb', line 137 def entry_to_formula(entry) Homebrew::Bundle::Brew.new(entry.name, entry.) end |
#failure_reason(name, no_upgrade:) ⇒ 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.
109 110 111 112 113 |
# File 'bundle/brew_services.rb', line 109 def failure_reason(name, no_upgrade:) _ = no_upgrade "Service #{name} needs to be started." end |
#format_checkable(entries) ⇒ Array<Object>
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.
155 156 157 |
# File 'bundle/brew_services.rb', line 155 def format_checkable(entries) checkable_entries(entries) end |
#formula_needs_to_start?(formula) ⇒ 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.
142 143 144 |
# File 'bundle/brew_services.rb', line 142 def formula_needs_to_start?(formula) formula.start_service? || formula.restart_service? end |
#installed_and_up_to_date?(formula, no_upgrade: false) ⇒ 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.
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'bundle/brew_services.rb', line 116 def installed_and_up_to_date?(formula, no_upgrade: false) _ = no_upgrade entry = T.cast(formula, Homebrew::Bundle::Dsl::Entry) return true unless formula_needs_to_start?(entry_to_formula(entry)) name = entry.name return true if self.class.started?(name) # `brew services list` returns base names, so fall back to the last # path component for tap-qualified entries (e.g., "user/tap/formula"). base_name = name.split("/").fetch(-1) return true if base_name != name && self.class.started?(base_name) old_name = lookup_old_name(name) return true if old_name && self.class.started?(old_name) false end |
#lookup_old_name(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.
147 148 149 150 151 152 |
# File 'bundle/brew_services.rb', line 147 def lookup_old_name(service_name) @old_names ||= T.let(Homebrew::Bundle::Brew.formula_oldnames, T.nilable(T::Hash[String, String])) old_name = @old_names[service_name] old_name ||= @old_names[service_name.split("/").fetch(-1)] old_name end |