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?. - #timer_dest ⇒ Pathname private
- #timer_file ⇒ Pathname private
- #timer_name ⇒ String private
- #to_hash ⇒ Hash{Symbol => T.anything} private
- #unknown_status? ⇒ Boolean private
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, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_outdated, #pretty_uninstalled, #pretty_upgradable
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.
130 131 132 |
# File 'services/formula_wrapper.rb', line 130 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.
124 125 126 |
# File 'services/formula_wrapper.rb', line 124 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.
208 209 210 211 212 |
# File 'services/formula_wrapper.rb', line 208 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.
227 228 229 |
# File 'services/formula_wrapper.rb', line 227 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.
136 137 138 |
# File 'services/formula_wrapper.rb', line 136 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.
Delegate access to formula.service.keep_alive?.
63 64 65 66 67 68 |
# File 'services/formula_wrapper.rb', line 63 def keep_alive? return @keep_alive unless @keep_alive.nil? @keep_alive = T.let(service? && load_service.keep_alive?, T.nilable(T::Boolean)) @keep_alive ||= false 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.
160 161 162 163 164 165 166 167 |
# File 'services/formula_wrapper.rb', line 160 def loaded?(cached: false) if System.launchctl? reset_cache! unless cached status_success else # System.systemctl? System::Systemctl.quiet_run("status", timed? ? timer_name : 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.
232 233 234 |
# File 'services/formula_wrapper.rb', line 232 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.
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'services/formula_wrapper.rb', line 184 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.
221 222 223 |
# File 'services/formula_wrapper.rb', line 221 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.
203 204 205 |
# File 'services/formula_wrapper.rb', line 203 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.
142 143 144 145 146 147 148 149 150 151 |
# File 'services/formula_wrapper.rb', line 142 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.
154 155 156 |
# File 'services/formula_wrapper.rb', line 154 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.
85 86 87 88 89 90 91 92 93 |
# File 'services/formula_wrapper.rb', line 85 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.
172 173 174 175 176 177 178 179 180 181 |
# File 'services/formula_wrapper.rb', line 172 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>).
73 74 75 76 77 78 79 80 81 |
# File 'services/formula_wrapper.rb', line 73 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
112 113 114 115 116 117 118 119 120 |
# File 'services/formula_wrapper.rb', line 112 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.
Delegate access to formula.service.timed?.
54 55 56 57 58 59 |
# File 'services/formula_wrapper.rb', line 54 def timed? return @timed unless @timed.nil? @timed = T.let(service? && load_service.timed?, T.nilable(T::Boolean)) @timed ||= false end |
#timer_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.
106 107 108 |
# File 'services/formula_wrapper.rb', line 106 def timer_dest dest_dir + timer_file.basename end |
#timer_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.
96 97 98 |
# File 'services/formula_wrapper.rb', line 96 def timer_file @timer_file ||= T.let(formula.systemd_timer_path, T.nilable(Pathname)) end |
#timer_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.
101 102 103 |
# File 'services/formula_wrapper.rb', line 101 def timer_name @timer_name ||= T.let(timer_file.basename.to_s, T.nilable(String)) 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.
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'services/formula_wrapper.rb', line 237 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.
215 216 217 |
# File 'services/formula_wrapper.rb', line 215 def unknown_status? status_output.blank? && !pid? end |