diff --git a/Library/Homebrew/service.rb b/Library/Homebrew/service.rb
index 77d3b47862..4725a8acb0 100644
--- a/Library/Homebrew/service.rb
+++ b/Library/Homebrew/service.rb
@@ -27,6 +27,7 @@ module Homebrew
def initialize(formula, &block)
@formula = formula
@run_type = RUN_TYPE_IMMEDIATE
+ @run_at_load = true
@environment_variables = {}
@service_block = block
end
@@ -159,6 +160,18 @@ module Homebrew
@require_root.present? && @require_root == true
end
+ sig { params(value: T.nilable(T::Boolean)).returns(T.nilable(T::Boolean)) }
+ def run_at_load(value = nil)
+ case T.unsafe(value)
+ when nil
+ @run_at_load
+ when true, false
+ @run_at_load = value
+ else
+ raise TypeError, "Service#run_at_load expects a Boolean"
+ end
+ end
+
sig { params(value: T.nilable(String)).returns(T.nilable(T::Hash[Symbol, String])) }
def sockets(value = nil)
case T.unsafe(value)
@@ -371,7 +384,7 @@ module Homebrew
base = {
Label: @formula.plist_name,
ProgramArguments: command,
- RunAtLoad: @run_type == RUN_TYPE_IMMEDIATE,
+ RunAtLoad: @run_at_load == true,
}
base[:LaunchOnlyOnce] = @launch_only_once if @launch_only_once == true
diff --git a/Library/Homebrew/test/service_spec.rb b/Library/Homebrew/test/service_spec.rb
index 6b08b4f03b..5554aa2860 100644
--- a/Library/Homebrew/test/service_spec.rb
+++ b/Library/Homebrew/test/service_spec.rb
@@ -346,6 +346,43 @@ describe Homebrew::Service do
expect(plist).to eq(plist_expect)
end
+ it "returns valid partial plist with run_at_load being false" do
+ f = stub_formula do
+ service do
+ run opt_bin/"beanstalkd"
+ run_type :immediate
+ run_at_load false
+ end
+ end
+
+ plist = f.service.to_plist
+ plist_expect = <<~EOS
+
+
+
+
+ \tLabel
+ \thomebrew.mxcl.formula_name
+ \tLimitLoadToSessionType
+ \t
+ \t\tAqua
+ \t\tBackground
+ \t\tLoginWindow
+ \t\tStandardIO
+ \t\tSystem
+ \t
+ \tProgramArguments
+ \t
+ \t\t#{HOMEBREW_PREFIX}/opt/formula_name/bin/beanstalkd
+ \t
+ \tRunAtLoad
+ \t
+
+
+ EOS
+ expect(plist).to eq(plist_expect)
+ end
+
it "returns valid interval plist" do
f = stub_formula do
service do
@@ -376,7 +413,7 @@ describe Homebrew::Service do
\t\t#{HOMEBREW_PREFIX}/opt/formula_name/bin/beanstalkd
\t
\tRunAtLoad
- \t
+ \t
\tStartInterval
\t5
@@ -415,7 +452,7 @@ describe Homebrew::Service do
\t\t#{HOMEBREW_PREFIX}/opt/formula_name/bin/beanstalkd
\t
\tRunAtLoad
- \t
+ \t
\tStartCalendarInterval
\t
\t\tHour