Class: Homebrew::Bundle::Brew::Services Private

Inherits:
Homebrew::Bundle::Brew show all
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.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils::Output::Mixin

issue_reporting_message, odebug, odeprecated, odie, odisabled, ofail, oh1, oh1_title, ohai, ohai_title, onoe, opoo, opoo_outside_github_actions, opoo_without_github_actions_annotation, pretty_deprecated, pretty_disabled, pretty_duration, pretty_install_status, pretty_installed, pretty_uninstalled, pretty_unmarked, pretty_upgradable, pretty_warning

Methods inherited from Homebrew::Bundle::Brew

#changed?, check_label, dump, dump_output, expected_link_status?, #find_actionable, find_formula, formula_aliases, formula_dump_link_status, formula_in_array?, formula_installed?, formula_installed_and_up_to_date?, formula_oldnames, formula_upgradable?, formulae, formulae_by_full_name, inherited, #initialize, install!, #install!, #install_change_state!, install_verb, installed_formulae, #link_change_state!, link_status_to_check, 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?, type, upgradable_formulae

Methods inherited from PackageType

batch_installable?, check, check_label, #checkable_entries, dump, dump_output, dump_supported?, #exit_early_check, #find_actionable, #full_check, inherited, install!, install_batch!, 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.

Parameters:

  • name (String)
  • file (String, nil) (defaults to: nil)
  • verbose (Boolean) (defaults to: false)

Returns:

  • (Boolean)


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.

Parameters:

  • name (String)
  • file (Pathname, String, nil) (defaults to: nil)
  • verbose (Boolean) (defaults to: false)

Returns:

  • (Boolean)


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

.service_file_for(formula, prefix) ⇒ 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.

Parameters:

Returns:



94
95
96
97
98
99
100
101
102
# File 'bundle/brew_services.rb', line 94

def service_file_for(formula, prefix)
  service_files = if Homebrew::Services::System.launchctl?
    formula.plist_names.map { |name| prefix/"#{name}.plist" }
  else
    [prefix/"#{formula.service_name}.service"]
  end

  service_files.find(&:file?)
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.

Parameters:

  • name (String)
  • file (String, nil) (defaults to: nil)
  • verbose (Boolean) (defaults to: false)

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


67
68
69
# File 'bundle/brew_services.rb', line 67

def started?(name)
  started_services.include? name
end

.started_servicesArray<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:



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'bundle/brew_services.rb', line 77

def started_services
  @started_services ||= T.let(
    if !Homebrew::Services::System.launchctl? && !Homebrew::Services::System.systemctl?
      started_services_without_daemon_manager
    else
      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

.started_services_without_daemon_managerArray<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:



72
73
74
# File 'bundle/brew_services.rb', line 72

def started_services_without_daemon_manager
  odie Homebrew::Services::System::MISSING_DAEMON_MANAGER_EXCEPTION_MESSAGE
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.

Parameters:

Returns:



105
106
107
108
109
110
111
112
113
114
# File 'bundle/brew_services.rb', line 105

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_for(formula, prefix)
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.

Parameters:

Returns:



146
147
148
# File 'bundle/brew_services.rb', line 146

def entry_to_formula(entry)
  Homebrew::Bundle::Brew.new(entry.name, entry.options)
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.

Parameters:

  • name (Object)
  • no_upgrade (Boolean)

Returns:



118
119
120
121
122
# File 'bundle/brew_services.rb', line 118

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.

Parameters:

Returns:



164
165
166
# File 'bundle/brew_services.rb', line 164

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.

Parameters:

Returns:

  • (Boolean)


151
152
153
# File 'bundle/brew_services.rb', line 151

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.

Parameters:

  • formula (Object)
  • no_upgrade (Boolean) (defaults to: false)

Returns:

  • (Boolean)


125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'bundle/brew_services.rb', line 125

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 = Utils.name_from_full_name(name)
  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.

Parameters:

Returns:



156
157
158
159
160
161
# File 'bundle/brew_services.rb', line 156

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[Utils.name_from_full_name(service_name)]
  old_name
end