Class: Homebrew::Services::FormulaWrapper Private
- Includes:
- Utils::Output::Mixin
- Defined in:
- services/formula_wrapper.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.
Defined Under Namespace
Classes: StatusOutputSuccessType
Instance Attribute Summary collapse
-
#formula ⇒ Formula
readonly
private
Access the
Formulainstance.
Class Method Summary collapse
-
.from(path_or_label) ⇒ FormulaWrapper?
private
Create a new
Serviceinstance from either a path or label.
Instance Method Summary collapse
-
#dest ⇒ Pathname
private
Path to destination service.
-
#dest_dir ⇒ Pathname
private
Path to destination service directory.
- #error? ⇒ Boolean private
-
#exit_code ⇒ Integer?
private
Get current exit code of daemon process from status output.
-
#initialize(formula) ⇒ void
constructor
private
Initialize a new
Serviceinstance with supplied formula. -
#installed? ⇒ Boolean
private
Returns
trueif any version of the formula is installed. -
#keep_alive? ⇒ Boolean?
private
Delegate access to
formula.service.keep_alive?. -
#loaded?(cached: false) ⇒ Boolean
private
Returns
trueif the service is loaded, else false. - #loaded_file ⇒ String? private
-
#name ⇒ String
private
Delegate access to
formula.name. - #owner ⇒ String? private
-
#pid ⇒ Integer?
private
Get current PID of daemon process from status output.
- #pid? ⇒ Boolean private
-
#plist? ⇒ Boolean
private
Returns
trueif the plist file exists. - #reset_cache! ⇒ void private
-
#service? ⇒ Boolean
private
Delegate access to
formula.service?. -
#service_file ⇒ Pathname
private
service_file delegates with formula.launchd_service_path or formula.systemd_service_path for systemd.
-
#service_file_present?(type: nil) ⇒ Boolean
private
Returns
trueif service is present (e.g. .plist is present in boot or user service path), elsefalseAcceptstypewith values:rootfor boot path or:userfor user path. -
#service_name ⇒ String
private
service_name delegates with formula.plist_name or formula.service_name for systemd (e.g.,
homebrew.<formula>). -
#service_startup? ⇒ Boolean
private
Whether the service should be launched at startup.
-
#timed? ⇒ Boolean?
private
Delegate access to
formula.service.timed?. - #to_hash ⇒ Hash{Symbol => T.anything} private
- #unknown_status? ⇒ Boolean 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_duration, #pretty_installed, #pretty_outdated, #pretty_uninstalled
Constructor Details
#initialize(formula) ⇒ 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.
Initialize a new Service instance with supplied formula.
31 32 33 34 35 36 37 38 |
# File 'services/formula_wrapper.rb', line 31 def initialize(formula) @formula = formula @status_output_success_type = T.let(nil, T.nilable(StatusOutputSuccessType)) return if System.launchctl? || System.systemctl? raise UsageError, System::MISSING_DAEMON_MANAGER_EXCEPTION_MESSAGE end |
Instance Attribute Details
#formula ⇒ Formula (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.
Access the Formula instance.
15 16 17 |
# File 'services/formula_wrapper.rb', line 15 def formula @formula end |
Class Method Details
.from(path_or_label) ⇒ FormulaWrapper?
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.
Create a new Service instance from either a path or label.
19 20 21 22 23 24 25 26 27 |
# File 'services/formula_wrapper.rb', line 19 def self.from(path_or_label) return unless path_or_label =~ path_or_label_regex begin new(Formulary.factory(T.must(Regexp.last_match(1)))) rescue nil end end |
Instance Method Details
#dest ⇒ 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.
Path to destination service. If run as root, it's in boot_path, else user_path.
111 112 113 |
# File 'services/formula_wrapper.rb', line 111 def dest dest_dir + service_file.basename end |
#dest_dir ⇒ 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.
Path to destination service directory. If run as root, it's boot_path, else user_path.
105 106 107 |
# File 'services/formula_wrapper.rb', line 105 def dest_dir System.root? ? System.boot_path : System.user_path end |
#error? ⇒ 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.
189 190 191 192 193 |
# File 'services/formula_wrapper.rb', line 189 def error? return false if pid? (exit_code = self.exit_code).present? && !exit_code.zero? end |
#exit_code ⇒ 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.
Get current exit code of daemon process from status output.
208 209 210 |
# File 'services/formula_wrapper.rb', line 208 def exit_code Regexp.last_match(1).to_i if status_output =~ exit_code_regex(status_type) end |
#installed? ⇒ 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 true if any version of the formula is installed.
117 118 119 |
# File 'services/formula_wrapper.rb', line 117 def installed? formula.any_version_installed? 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.
this should either be T::Boolean or renamed to keep_alive
Delegate access to formula.service.keep_alive?.
62 63 64 |
# File 'services/formula_wrapper.rb', line 62 def keep_alive? @keep_alive ||= T.let((load_service.keep_alive? if service?), T.nilable(T::Boolean)) end |
#loaded?(cached: 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.
Returns true if the service is loaded, else false.
141 142 143 144 145 146 147 148 |
# File 'services/formula_wrapper.rb', line 141 def loaded?(cached: false) if System.launchctl? reset_cache! unless cached status_success else # System.systemctl? System::Systemctl.quiet_run("status", service_file.basename) end end |
#loaded_file ⇒ 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.
213 214 215 |
# File 'services/formula_wrapper.rb', line 213 def loaded_file Regexp.last_match(1) if status_output =~ loaded_file_regex(status_type) end |
#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.
Delegate access to formula.name.
42 43 44 |
# File 'services/formula_wrapper.rb', line 42 def name @name ||= T.let(formula.name, T.nilable(String)) end |
#owner ⇒ 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.
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'services/formula_wrapper.rb', line 165 def owner if System.launchctl? && dest.exist? # read the username from the plist file plist = begin Plist.parse_xml(dest.read, marshal: false) rescue nil end plist_username = plist["UserName"] if plist return plist_username if plist_username.present? end return "root" if boot_path_service_file_present? return System.user if user_path_service_file_present? nil end |
#pid ⇒ 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.
Get current PID of daemon process from status output.
202 203 204 |
# File 'services/formula_wrapper.rb', line 202 def pid Regexp.last_match(1).to_i if status_output =~ pid_regex(status_type) end |
#pid? ⇒ 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.
184 185 186 |
# File 'services/formula_wrapper.rb', line 184 def pid? (pid = self.pid).present? && pid.positive? end |
#plist? ⇒ 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 true if the plist file exists.
123 124 125 126 127 128 129 130 131 132 |
# File 'services/formula_wrapper.rb', line 123 def plist? return false unless installed? return true if service_file.file? return false unless formula.opt_prefix.exist? return true if Keg.for(formula.opt_prefix).plist_installed? false rescue NotAKegError false end |
#reset_cache! ⇒ 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.
135 136 137 |
# File 'services/formula_wrapper.rb', line 135 def reset_cache! @status_output_success_type = nil end |
#service? ⇒ 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.
Delegate access to formula.service?.
48 49 50 |
# File 'services/formula_wrapper.rb', line 48 def service? @service ||= T.let(formula.service?, T.nilable(T::Boolean)) end |
#service_file ⇒ 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.
service_file delegates with formula.launchd_service_path or formula.systemd_service_path for systemd.
81 82 83 84 85 86 87 88 89 |
# File 'services/formula_wrapper.rb', line 81 def service_file @service_file ||= T.let( if System.launchctl? formula.launchd_service_path else # System.systemctl? formula.systemd_service_path end, T.nilable(Pathname) ) end |
#service_file_present?(type: 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.
Returns true if service is present (e.g. .plist is present in boot or user service path), else false
Accepts type with values :root for boot path or :user for user path.
153 154 155 156 157 158 159 160 161 162 |
# File 'services/formula_wrapper.rb', line 153 def service_file_present?(type: nil) case type when :root boot_path_service_file_present? when :user user_path_service_file_present? else boot_path_service_file_present? || user_path_service_file_present? end end |
#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.
service_name delegates with formula.plist_name or formula.service_name
for systemd (e.g., homebrew.<formula>).
69 70 71 72 73 74 75 76 77 |
# File 'services/formula_wrapper.rb', line 69 def service_name @service_name ||= T.let( if System.launchctl? formula.plist_name else # System.systemctl? formula.service_name end, T.nilable(String) ) end |
#service_startup? ⇒ 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.
Whether the service should be launched at startup
93 94 95 96 97 98 99 100 101 |
# File 'services/formula_wrapper.rb', line 93 def service_startup? @service_startup ||= T.let( if service? load_service.requires_root? else false end, T.nilable(T::Boolean) ) 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.
this should either be T::Boolean or renamed to timed
Delegate access to formula.service.timed?.
55 56 57 |
# File 'services/formula_wrapper.rb', line 55 def timed? @timed ||= T.let((load_service.timed? if service?), T.nilable(T::Boolean)) end |
#to_hash ⇒ Hash{Symbol => T.anything}
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.
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'services/formula_wrapper.rb', line 218 def to_hash hash = { name:, service_name:, running: pid?, loaded: loaded?(cached: true), schedulable: timed?, pid:, exit_code:, user: owner, status: status_symbol, file: service_file_present? ? dest : service_file, registered: service_file_present?, loaded_file:, } return hash unless service? service = load_service return hash if service.command.blank? hash[:command] = service.manual_command hash[:working_dir] = service.working_dir hash[:root_dir] = service.root_dir hash[:log_path] = service.log_path hash[:error_log_path] = service.error_log_path hash[:interval] = service.interval hash[:cron] = service.cron.presence hash end |
#unknown_status? ⇒ 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.
196 197 198 |
# File 'services/formula_wrapper.rb', line 196 def unknown_status? status_output.blank? && !pid? end |