Class: Homebrew::Cmd::Services Private

Inherits:
AbstractCommand show all
Extended by:
Utils::Output::Mixin
Defined in:
cmd/services.rb,
services/subcommand.rb,
services/subcommand/run.rb,
services/subcommand/info.rb,
services/subcommand/kill.rb,
services/subcommand/list.rb,
services/subcommand/stop.rb,
services/subcommand/start.rb,
services/subcommand/cleanup.rb,
services/subcommand/restart.rb,
sorbet/rbi/dsl/homebrew/cmd/services.rbi

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: Args, CleanupSubcommand, InfoSubcommand, KillSubcommand, ListSubcommand, RestartSubcommand, RunSubcommand, StartSubcommand, StopSubcommand

Class Method Summary collapse

Instance Method Summary collapse

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_outdated, pretty_uninstalled, pretty_upgradable

Methods inherited from AbstractCommand

command, command_name, dev_cmd?, #initialize, parser, ruby_cmd?

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Class Method Details

.dispatch(args) ⇒ 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.

Parameters:

  • args (T.untyped)


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'services/subcommand.rb', line 22

def dispatch(args)
  # pbpaste's exit status is a proxy for detecting the use of reattach-to-user-namespace
  if ENV.fetch("HOMEBREW_TMUX", nil) && File.exist?("/usr/bin/pbpaste") && !quiet_system("/usr/bin/pbpaste")
    raise UsageError,
          "`brew services` cannot run under tmux!"
  end

  # Keep this after the .parse to keep --help fast.
  require "utils"

  if !Homebrew::Services::System.launchctl? && !Homebrew::Services::System.systemctl?
    raise UsageError, Homebrew::Services::System::MISSING_DAEMON_MANAGER_EXCEPTION_MESSAGE
  end

  if (sudo_service_user = args.sudo_service_user)
    unless Homebrew::Services::System.root?
      raise UsageError,
            "`brew services` is supported only when running as root!"
    end

    unless Homebrew::Services::System.launchctl?
      raise UsageError,
            "`brew services --sudo-service-user` is currently supported only on macOS " \
            "(but we'd love a PR to add Linux support)!"
    end

    Homebrew::Services::Cli.sudo_service_user = sudo_service_user
  end

  subcommand = args.subcommand
  formulae = args.named

  opoo "The `--all` argument overrides provided formula argument!" if formulae.present? && args.all?

  targets = targets(args, subcommand:, formulae:)

  # Exit successfully if --all was used but there is nothing to do
  return if args.all? && targets.empty?

  if Homebrew::Services::System.systemctl?
    ENV["DBUS_SESSION_BUS_ADDRESS"] = ENV.fetch("HOMEBREW_DBUS_SESSION_BUS_ADDRESS", nil)
    ENV["XDG_RUNTIME_DIR"] = ENV.fetch("HOMEBREW_XDG_RUNTIME_DIR", nil)
  end

  subcommand_class = Homebrew::AbstractSubcommand.subcommands_for(Homebrew::Cmd::Services).find do |candidate|
    candidate.subcommand_name == subcommand
  end
  T.must(subcommand_class).new(args, targets:).run
end

.targets(args, subcommand:, formulae:) ⇒ Array<Homebrew::Services::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.

Parameters:

Returns:



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'services/subcommand.rb', line 76

def targets(args, subcommand:, formulae:)
  if args.all?
    if subcommand == "start"
      Homebrew::Services::Formulae.available_services(
        loaded:    false,
        skip_root: !Homebrew::Services::System.root?,
      )
    elsif subcommand == "stop"
      Homebrew::Services::Formulae.available_services(
        loaded:    true,
        skip_root: !Homebrew::Services::System.root?,
      )
    else
      Homebrew::Services::Formulae.available_services
    end
  elsif formulae.present?
    formulae.map { |formula| Homebrew::Services::FormulaWrapper.new(Formulary.factory(formula)) }
  else
    []
  end
end

Instance Method Details

#argsHomebrew::Cmd::Services::Args

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.



10
# File 'sorbet/rbi/dsl/homebrew/cmd/services.rbi', line 10

def args; end

#runvoid

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.



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

def run
  Homebrew::Cmd::Services.dispatch(args)
end