Module: Homebrew::Services::System Private
- Extended by:
- Utils::Output::Mixin
- Defined in:
- services/system.rb,
services/system/systemctl.rb
This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.
Defined Under Namespace
Modules: Systemctl
Constant Summary collapse
- LAUNCHCTL_DOMAIN_ACTION_NOT_SUPPORTED =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
125- MISSING_DAEMON_MANAGER_EXCEPTION_MESSAGE =
This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.
"`brew services` is supported only on macOS or Linux (with systemd)!"
Class Attribute Summary collapse
-
.launchctl ⇒ Pathname?
private
Path to launchctl binary.
Class Method Summary collapse
-
.boot_path ⇒ Pathname
private
Run at boot.
- .candidate_domain_targets ⇒ Array<String> private
- .domain_target ⇒ String private
-
.launchctl? ⇒ Boolean
private
Is this a launchctl system.
-
.launchctl_find_service(label, sudo: false) ⇒ Array<(String, Boolean, Symbol)>
private
Probe for a launchd service across all candidate domains.
-
.launchctl_service_running?(label, sudo: false) ⇒ Boolean
private
Check if a launchd service is running, given its label (e.g.
homebrew.mxcl.foo). -
.path ⇒ Pathname
private
If root, return
boot_path, else returnuser_path. -
.root? ⇒ Boolean
private
Woohoo, we are root dude!.
-
.systemctl? ⇒ Boolean
private
Is this a systemd system.
-
.user ⇒ String?
private
Current user running
[sudo] brew services. - .user_exists?(username) ⇒ Boolean private
-
.user_path ⇒ Pathname
private
Run at login.
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
Class Attribute Details
.launchctl ⇒ 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 launchctl binary.
19 20 21 |
# File 'services/system.rb', line 19 def self.launchctl @launchctl ||= T.let(which("launchctl"), T.nilable(Pathname)) end |
Class Method Details
.boot_path ⇒ 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.
Run at boot.
66 67 68 69 70 71 72 73 74 |
# File 'services/system.rb', line 66 def self.boot_path if launchctl? Pathname.new("/Library/LaunchDaemons") elsif systemctl? Pathname.new("/usr/lib/systemd/system") else raise UsageError, MISSING_DAEMON_MANAGER_EXCEPTION_MESSAGE end end |
.candidate_domain_targets ⇒ 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.
123 124 125 126 127 |
# File 'services/system.rb', line 123 def self.candidate_domain_targets candidates = [domain_target] candidates += ["user/#{Process.euid}", "gui/#{Process.uid}"] unless root? candidates.uniq end |
.domain_target ⇒ 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.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'services/system.rb', line 95 def self.domain_target if root? "system" elsif (ssh_tty = ENV.fetch("HOMEBREW_SSH_TTY", nil).present? && File.stat("/dev/console").uid != Process.uid) || (sudo_user = ENV.fetch("HOMEBREW_SUDO_USER", nil).present?) || (Process.uid != Process.euid) if @output_warning.blank? && ENV.fetch("HOMEBREW_SERVICES_NO_DOMAIN_WARNING", nil).blank? if ssh_tty opoo "running over SSH without /dev/console ownership, using user/* instead of gui/* domain!" elsif sudo_user opoo "running through sudo, using user/* instead of gui/* domain!" else opoo "uid and euid do not match, using user/* instead of gui/* domain!" end unless Homebrew::EnvConfig.no_env_hints? $stderr.puts "Hide this warning by setting `HOMEBREW_SERVICES_NO_DOMAIN_WARNING=1`." $stderr.puts "Hide these hints with `HOMEBREW_NO_ENV_HINTS=1` (see `man brew`)." end @output_warning = T.let(true, T.nilable(TrueClass)) end "user/#{Process.euid}" else "gui/#{Process.uid}" end end |
.launchctl? ⇒ 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.
Is this a launchctl system
30 31 32 |
# File 'services/system.rb', line 30 def self.launchctl? launchctl.present? end |
.launchctl_find_service(label, sudo: false) ⇒ Array<(String, Boolean, Symbol)>
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.
Probe for a launchd service across all candidate domains.
Returns output text, success flag, and the command type used
(:launchctl_print or :launchctl_list). Pass sudo: true to run
the probe with elevated privileges (e.g. for system-owned services).
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'services/system.rb', line 134 def self.launchctl_find_service(label, sudo: false) launchctl_path = launchctl return ["", false, :launchctl_list] unless launchctl_path candidate_domain_targets.each do |domain| cmd = [launchctl_path.to_s, "print", "#{domain}/#{label}"] output, success = launchctl_run(cmd, sudo:) if success && output.present? odebug cmd.join(" "), output return [output, true, :launchctl_print] end end cmd = [launchctl_path.to_s, "list", label] output, success = launchctl_run(cmd, sudo:) odebug cmd.join(" "), output [output, success && output.present?, :launchctl_list] end |
.launchctl_service_running?(label, sudo: 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.
Check if a launchd service is running, given its label (e.g. homebrew.mxcl.foo).
Tries domain-qualified lookups first, then falls back to a bare label search.
156 157 158 159 |
# File 'services/system.rb', line 156 def self.launchctl_service_running?(label, sudo: false) _, success, = launchctl_find_service(label, sudo:) success end |
.path ⇒ 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.
If root, return boot_path, else return user_path.
90 91 92 |
# File 'services/system.rb', line 90 def self.path root? ? boot_path : user_path end |
.root? ⇒ 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.
Woohoo, we are root dude!
42 43 44 |
# File 'services/system.rb', line 42 def self.root? Process.euid.zero? end |
.systemctl? ⇒ 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.
Is this a systemd system
36 37 38 |
# File 'services/system.rb', line 36 def self.systemctl? Systemctl.executable.present? end |
.user ⇒ 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.
Current user running [sudo] brew services.
48 49 50 |
# File 'services/system.rb', line 48 def self.user @user ||= T.let(ENV["USER"].presence || Utils.safe_popen_read("/usr/bin/whoami").chomp, T.nilable(String)) end |
.user_exists?(username) ⇒ 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.
53 54 55 56 57 58 59 60 61 62 |
# File 'services/system.rb', line 53 def self.user_exists?(username) # Current user must be present return true if username == user # Check other users Etc.getpwnam(username) true rescue ArgumentError false end |
.user_path ⇒ 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.
Run at login.
78 79 80 81 82 83 84 85 86 |
# File 'services/system.rb', line 78 def self.user_path if launchctl? Pathname.new("#{Dir.home}/Library/LaunchAgents") elsif systemctl? Pathname.new("#{Dir.home}/.config/systemd/user") else raise UsageError, MISSING_DAEMON_MANAGER_EXCEPTION_MESSAGE end end |