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_upgradable, pretty_warning

Methods inherited from Homebrew::Bundle::Brew

#changed?, check_label, dump, dump_output, expected_link_status?, fetchable_name, #find_actionable, find_formula, formula_aliases, formula_dep_names, formula_dump_link_status, 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!, link_status_to_check, no_upgrade_with_args?, outdated_formulae, pinned_formulae, #postinstall_change_state!, preinstall!, #preinstall!, recursive_dep_names, #restart_service?, #restart_service_needed?, #service_change_state!, #start_service?, #start_service_needed?, type, upgradable_formulae

Methods inherited from PackageType

check, check_label, #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.

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

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



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'bundle/brew_services.rb', line 94

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.

Parameters:

Returns:



141
142
143
# File 'bundle/brew_services.rb', line 141

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:



113
114
115
116
117
# File 'bundle/brew_services.rb', line 113

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:



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

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)


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

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)


120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'bundle/brew_services.rb', line 120

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:



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

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