Module: Utils::Service Private
- Defined in:
- utils/service.rb
Overview
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.
Helpers for brew services related code.
Class Method Summary collapse
-
.installed?(formula) ⇒ Boolean
private
Check if a service file is installed in the expected location.
-
.launchctl ⇒ Pathname?
private
Path to launchctl binary.
- .launchctl? ⇒ Boolean private
-
.running?(formula) ⇒ Boolean
private
Check if a service is running for a specified formula.
-
.systemctl ⇒ Pathname?
private
Path to systemctl binary.
- .systemctl? ⇒ Boolean private
-
.systemd_quote(str) ⇒ String
private
Quote a string for use in systemd command lines, e.g., in
ExecStart.
Class Method Details
.installed?(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.
Check if a service file is installed in the expected location.
29 30 31 32 |
# File 'utils/service.rb', line 29 def self.installed?(formula) (launchctl? && formula.launchd_service_paths.any?(&:exist?)) || (systemctl? && formula.systemd_service_paths.any?(&:exist?)) end |
.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.
36 37 38 39 40 41 |
# File 'utils/service.rb', line 36 def self.launchctl return @launchctl if defined? @launchctl return if ENV["HOMEBREW_TEST_GENERIC_OS"] @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.
53 54 55 |
# File 'utils/service.rb', line 53 def self.launchctl? !launchctl.nil? end |
.running?(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.
Check if a service is running for a specified formula.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'utils/service.rb', line 13 def self.running?(formula) if launchctl? formula.plist_names.any? do |name| Homebrew::Services::System.launchctl_service_running?(name) end elsif systemctl? formula.service_names.any? do |name| SystemCommand.quiet_system(systemctl, "is-active", "--quiet", name) end else false end end |
.systemctl ⇒ 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 systemctl binary.
45 46 47 48 49 50 |
# File 'utils/service.rb', line 45 def self.systemctl return @systemctl if defined? @systemctl return if ENV["HOMEBREW_TEST_GENERIC_OS"] @systemctl = T.let(which("systemctl"), T.nilable(Pathname)) 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.
58 59 60 |
# File 'utils/service.rb', line 58 def self.systemctl? !systemctl.nil? end |
.systemd_quote(str) ⇒ 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.
Quote a string for use in systemd command lines, e.g., in ExecStart.
https://www.freedesktop.org/software/systemd/man/latest/systemd.syntax.html#Quoting
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'utils/service.rb', line 65 def self.systemd_quote(str) result = +"\"" # No need to escape single quotes and spaces, as we're always double # quoting the entire string. str.each_char do |char| result << case char when "\a" then "\\a" when "\b" then "\\b" when "\f" then "\\f" when "\n" then "\\n" when "\r" then "\\r" when "\t" then "\\t" when "\v" then "\\v" when "\\" then "\\\\" when "\"" then "\\\"" else char end end result << "\"" result.freeze end |