Module: Homebrew::Services::System Private

Extended by:
FileUtils
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

Class Method Summary collapse

Class Method Details

.boot_pathPathname?

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.

Returns:



52
53
54
55
56
57
58
# File 'services/system.rb', line 52

def self.boot_path
  if launchctl?
    Pathname.new("/Library/LaunchDaemons")
  elsif systemctl?
    Pathname.new("/usr/lib/systemd/system")
  end
end

.domain_targetString

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
92
93
94
95
96
97
98
99
100
101
102
# File 'services/system.rb', line 77

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?
        puts "Hide this warning by setting HOMEBREW_SERVICES_NO_DOMAIN_WARNING."
        puts "Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`)."
      end
      @output_warning = T.let(true, T.nilable(TrueClass))
    end
    "user/#{Process.euid}"
  else
    "gui/#{Process.uid}"
  end
end

.launchctlPathname?

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.

Returns:



13
14
15
# File 'services/system.rb', line 13

def self.launchctl
  @launchctl ||= T.let(which("launchctl"), T.nilable(Pathname))
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

Returns:

  • (Boolean)


19
20
21
# File 'services/system.rb', line 19

def self.launchctl?
  launchctl.present?
end

.pathPathname?

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.

Returns:



72
73
74
# File 'services/system.rb', line 72

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!

Returns:

  • (Boolean)


31
32
33
# File 'services/system.rb', line 31

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

Returns:

  • (Boolean)


25
26
27
# File 'services/system.rb', line 25

def self.systemctl?
  Systemctl.executable.present?
end

.userString?

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.

Returns:



37
38
39
# File 'services/system.rb', line 37

def self.user
  @user ||= T.let(ENV["USER"].presence || Utils.safe_popen_read("/usr/bin/whoami").chomp, T.nilable(String))
end

.user_of_process(pid) ⇒ 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:

  • pid (Integer, nil)

Returns:



42
43
44
45
46
47
48
# File 'services/system.rb', line 42

def self.user_of_process(pid)
  if pid.nil? || pid.zero?
    user
  else
    Utils.safe_popen_read("ps", "-o", "user", "-p", pid.to_s).lines.second&.chomp
  end
end

.user_pathPathname?

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.

Returns:



62
63
64
65
66
67
68
# File 'services/system.rb', line 62

def self.user_path
  if launchctl?
    Pathname.new("#{Dir.home}/Library/LaunchAgents")
  elsif systemctl?
    Pathname.new("#{Dir.home}/.config/systemd/user")
  end
end