Merge pull request #14624 from DenizUgur/service_run_at_load
dedicated `run_at_load` property
This commit is contained in:
commit
c0bae192e5
@ -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
|
||||
|
||||
@ -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
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
\t<key>Label</key>
|
||||
\t<string>homebrew.mxcl.formula_name</string>
|
||||
\t<key>LimitLoadToSessionType</key>
|
||||
\t<array>
|
||||
\t\t<string>Aqua</string>
|
||||
\t\t<string>Background</string>
|
||||
\t\t<string>LoginWindow</string>
|
||||
\t\t<string>StandardIO</string>
|
||||
\t\t<string>System</string>
|
||||
\t</array>
|
||||
\t<key>ProgramArguments</key>
|
||||
\t<array>
|
||||
\t\t<string>#{HOMEBREW_PREFIX}/opt/formula_name/bin/beanstalkd</string>
|
||||
\t</array>
|
||||
\t<key>RunAtLoad</key>
|
||||
\t<false/>
|
||||
</dict>
|
||||
</plist>
|
||||
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<string>#{HOMEBREW_PREFIX}/opt/formula_name/bin/beanstalkd</string>
|
||||
\t</array>
|
||||
\t<key>RunAtLoad</key>
|
||||
\t<false/>
|
||||
\t<true/>
|
||||
\t<key>StartInterval</key>
|
||||
\t<integer>5</integer>
|
||||
</dict>
|
||||
@ -415,7 +452,7 @@ describe Homebrew::Service do
|
||||
\t\t<string>#{HOMEBREW_PREFIX}/opt/formula_name/bin/beanstalkd</string>
|
||||
\t</array>
|
||||
\t<key>RunAtLoad</key>
|
||||
\t<false/>
|
||||
\t<true/>
|
||||
\t<key>StartCalendarInterval</key>
|
||||
\t<dict>
|
||||
\t\t<key>Hour</key>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user