2020-12-11 23:14:50 +01:00
|
|
|
# typed: false
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "formula"
|
|
|
|
require "service"
|
|
|
|
|
|
|
|
describe Homebrew::Service do
|
2022-08-24 23:52:40 +01:00
|
|
|
let(:name) { "formula_name" }
|
|
|
|
|
|
|
|
def stub_formula(&block)
|
|
|
|
formula(name) do
|
2020-12-11 23:14:50 +01:00
|
|
|
url "https://brew.sh/test-1.0.tbz"
|
2022-08-24 23:52:40 +01:00
|
|
|
|
|
|
|
instance_eval(&block) if block
|
2020-12-11 23:14:50 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-13 16:59:59 +02:00
|
|
|
describe "#std_service_path_env" do
|
|
|
|
it "returns valid std_service_path_env" do
|
2022-08-24 23:52:40 +01:00
|
|
|
f = stub_formula do
|
|
|
|
service do
|
|
|
|
run opt_bin/"beanstalkd"
|
|
|
|
run_type :immediate
|
|
|
|
environment_variables PATH: std_service_path_env
|
|
|
|
error_log_path var/"log/beanstalkd.error.log"
|
|
|
|
log_path var/"log/beanstalkd.log"
|
|
|
|
working_dir var
|
|
|
|
keep_alive true
|
|
|
|
end
|
2021-04-13 16:59:59 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
path = f.service.std_service_path_env
|
|
|
|
expect(path).to eq("#{HOMEBREW_PREFIX}/bin:#{HOMEBREW_PREFIX}/sbin:/usr/bin:/bin:/usr/sbin:/sbin")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-11-21 14:25:40 +01:00
|
|
|
describe "#process_type" do
|
|
|
|
it "throws for unexpected type" do
|
2022-08-24 23:52:40 +01:00
|
|
|
f = stub_formula do
|
|
|
|
service do
|
|
|
|
run opt_bin/"beanstalkd"
|
|
|
|
process_type :cow
|
|
|
|
end
|
2021-11-02 17:17:45 +01:00
|
|
|
end
|
|
|
|
|
2021-11-21 14:25:40 +01:00
|
|
|
expect {
|
|
|
|
f.service.manual_command
|
|
|
|
}.to raise_error TypeError, "Service#process_type allows: 'background'/'standard'/'interactive'/'adaptive'"
|
2021-11-02 17:17:45 +01:00
|
|
|
end
|
2021-11-21 14:25:40 +01:00
|
|
|
end
|
2021-11-02 17:17:45 +01:00
|
|
|
|
2022-01-25 19:29:16 +01:00
|
|
|
describe "#keep_alive" do
|
|
|
|
it "throws for unexpected keys" do
|
2022-08-24 23:52:40 +01:00
|
|
|
f = stub_formula do
|
|
|
|
service do
|
|
|
|
run opt_bin/"beanstalkd"
|
|
|
|
keep_alive test: "key"
|
|
|
|
end
|
2022-01-25 19:29:16 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
expect {
|
|
|
|
f.service.manual_command
|
|
|
|
}.to raise_error TypeError, "Service#keep_alive allows only [:always, :successful_exit, :crashed, :path]"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-11-06 13:52:53 +01:00
|
|
|
describe "#requires_root?" do
|
|
|
|
it "returns status when set" do
|
|
|
|
f = stub_formula do
|
|
|
|
service do
|
|
|
|
run opt_bin/"beanstalkd"
|
|
|
|
require_root true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(f.service.requires_root?).to be(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns status when not set" do
|
|
|
|
f = stub_formula do
|
|
|
|
service do
|
|
|
|
run opt_bin/"beanstalkd"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(f.service.requires_root?).to be(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-11-21 14:25:40 +01:00
|
|
|
describe "#run_type" do
|
2021-11-02 17:17:45 +01:00
|
|
|
it "throws for unexpected type" do
|
2022-08-24 23:52:40 +01:00
|
|
|
f = stub_formula do
|
|
|
|
service do
|
|
|
|
run opt_bin/"beanstalkd"
|
|
|
|
run_type :cow
|
|
|
|
end
|
2021-11-02 17:17:45 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
expect {
|
|
|
|
f.service.manual_command
|
|
|
|
}.to raise_error TypeError, "Service#run_type allows: 'immediate'/'interval'/'cron'"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-01-25 19:29:16 +01:00
|
|
|
describe "#sockets" do
|
|
|
|
it "throws for missing type" do
|
2022-08-24 23:52:40 +01:00
|
|
|
f = stub_formula do
|
|
|
|
service do
|
|
|
|
run opt_bin/"beanstalkd"
|
|
|
|
sockets "127.0.0.1:80"
|
|
|
|
end
|
2022-01-25 19:29:16 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
expect {
|
|
|
|
f.service.manual_command
|
|
|
|
}.to raise_error TypeError, "Service#sockets a formatted socket definition as <type>://<host>:<port>"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "throws for missing host" do
|
2022-08-24 23:52:40 +01:00
|
|
|
f = stub_formula do
|
|
|
|
service do
|
|
|
|
run opt_bin/"beanstalkd"
|
|
|
|
sockets "tcp://:80"
|
|
|
|
end
|
2022-01-25 19:29:16 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
expect {
|
|
|
|
f.service.manual_command
|
|
|
|
}.to raise_error TypeError, "Service#sockets a formatted socket definition as <type>://<host>:<port>"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "throws for missing port" do
|
2022-08-24 23:52:40 +01:00
|
|
|
f = stub_formula do
|
|
|
|
service do
|
|
|
|
run opt_bin/"beanstalkd"
|
|
|
|
sockets "tcp://127.0.0.1"
|
|
|
|
end
|
2022-01-25 19:29:16 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
expect {
|
|
|
|
f.service.manual_command
|
|
|
|
}.to raise_error TypeError, "Service#sockets a formatted socket definition as <type>://<host>:<port>"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-05-22 10:59:28 +02:00
|
|
|
describe "#manual_command" do
|
|
|
|
it "returns valid manual_command" do
|
2022-08-24 23:52:40 +01:00
|
|
|
f = stub_formula do
|
|
|
|
service do
|
|
|
|
run "#{HOMEBREW_PREFIX}/bin/beanstalkd"
|
|
|
|
run_type :immediate
|
|
|
|
environment_variables PATH: std_service_path_env, ETC_DIR: etc/"beanstalkd"
|
|
|
|
error_log_path var/"log/beanstalkd.error.log"
|
|
|
|
log_path var/"log/beanstalkd.log"
|
|
|
|
working_dir var
|
|
|
|
keep_alive true
|
|
|
|
end
|
2021-05-22 10:59:28 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
path = f.service.manual_command
|
|
|
|
expect(path).to eq("ETC_DIR=\"#{HOMEBREW_PREFIX}/etc/beanstalkd\" #{HOMEBREW_PREFIX}/bin/beanstalkd")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns valid manual_command without variables" do
|
2022-08-24 23:52:40 +01:00
|
|
|
f = stub_formula do
|
|
|
|
service do
|
|
|
|
run opt_bin/"beanstalkd"
|
|
|
|
run_type :immediate
|
|
|
|
environment_variables PATH: std_service_path_env
|
|
|
|
error_log_path var/"log/beanstalkd.error.log"
|
|
|
|
log_path var/"log/beanstalkd.log"
|
|
|
|
working_dir var
|
|
|
|
keep_alive true
|
|
|
|
end
|
2021-05-22 10:59:28 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
path = f.service.manual_command
|
|
|
|
expect(path).to eq("#{HOMEBREW_PREFIX}/opt/formula_name/bin/beanstalkd")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-12-11 23:14:50 +01:00
|
|
|
describe "#to_plist" do
|
|
|
|
it "returns valid plist" do
|
2022-08-24 23:52:40 +01:00
|
|
|
f = stub_formula do
|
|
|
|
service do
|
|
|
|
run [opt_bin/"beanstalkd", "test"]
|
|
|
|
run_type :immediate
|
|
|
|
environment_variables PATH: std_service_path_env, FOO: "BAR", ETC_DIR: etc/"beanstalkd"
|
|
|
|
error_log_path var/"log/beanstalkd.error.log"
|
|
|
|
log_path var/"log/beanstalkd.log"
|
|
|
|
input_path var/"in/beanstalkd"
|
2022-11-06 13:52:53 +01:00
|
|
|
require_root true
|
2022-08-24 23:52:40 +01:00
|
|
|
root_dir var
|
|
|
|
working_dir var
|
|
|
|
keep_alive true
|
|
|
|
launch_only_once true
|
|
|
|
process_type :interactive
|
|
|
|
restart_delay 30
|
|
|
|
interval 5
|
|
|
|
macos_legacy_timers true
|
|
|
|
end
|
2020-12-11 23:14:50 +01:00
|
|
|
end
|
|
|
|
|
2021-04-08 10:06:45 +02:00
|
|
|
plist = f.service.to_plist
|
2021-04-29 09:43:39 +02:00
|
|
|
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>EnvironmentVariables</key>
|
|
|
|
\t<dict>
|
2021-05-22 10:43:39 +02:00
|
|
|
\t\t<key>ETC_DIR</key>
|
|
|
|
\t\t<string>#{HOMEBREW_PREFIX}/etc/beanstalkd</string>
|
2021-05-22 10:59:28 +02:00
|
|
|
\t\t<key>FOO</key>
|
|
|
|
\t\t<string>BAR</string>
|
2021-04-29 09:43:39 +02:00
|
|
|
\t\t<key>PATH</key>
|
|
|
|
\t\t<string>#{HOMEBREW_PREFIX}/bin:#{HOMEBREW_PREFIX}/sbin:/usr/bin:/bin:/usr/sbin:/sbin</string>
|
|
|
|
\t</dict>
|
|
|
|
\t<key>KeepAlive</key>
|
|
|
|
\t<true/>
|
|
|
|
\t<key>Label</key>
|
|
|
|
\t<string>homebrew.mxcl.formula_name</string>
|
2022-02-04 11:42:25 -06:00
|
|
|
\t<key>LaunchOnlyOnce</key>
|
|
|
|
\t<true/>
|
2021-05-22 18:17:36 +02:00
|
|
|
\t<key>LegacyTimers</key>
|
|
|
|
\t<true/>
|
2022-07-03 16:25:19 +02:00
|
|
|
\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>
|
2021-09-08 21:54:13 -07:00
|
|
|
\t<key>ProcessType</key>
|
|
|
|
\t<string>Interactive</string>
|
2021-04-29 09:43:39 +02:00
|
|
|
\t<key>ProgramArguments</key>
|
|
|
|
\t<array>
|
|
|
|
\t\t<string>#{HOMEBREW_PREFIX}/opt/formula_name/bin/beanstalkd</string>
|
|
|
|
\t\t<string>test</string>
|
|
|
|
\t</array>
|
2021-05-22 18:17:36 +02:00
|
|
|
\t<key>RootDirectory</key>
|
|
|
|
\t<string>#{HOMEBREW_PREFIX}/var</string>
|
2021-04-29 09:43:39 +02:00
|
|
|
\t<key>RunAtLoad</key>
|
|
|
|
\t<true/>
|
|
|
|
\t<key>StandardErrorPath</key>
|
|
|
|
\t<string>#{HOMEBREW_PREFIX}/var/log/beanstalkd.error.log</string>
|
2021-05-22 18:17:36 +02:00
|
|
|
\t<key>StandardInPath</key>
|
|
|
|
\t<string>#{HOMEBREW_PREFIX}/var/in/beanstalkd</string>
|
2021-04-29 09:43:39 +02:00
|
|
|
\t<key>StandardOutPath</key>
|
|
|
|
\t<string>#{HOMEBREW_PREFIX}/var/log/beanstalkd.log</string>
|
2021-05-22 18:17:36 +02:00
|
|
|
\t<key>TimeOut</key>
|
|
|
|
\t<integer>30</integer>
|
2021-04-29 09:43:39 +02:00
|
|
|
\t<key>WorkingDirectory</key>
|
|
|
|
\t<string>#{HOMEBREW_PREFIX}/var</string>
|
|
|
|
</dict>
|
|
|
|
</plist>
|
|
|
|
EOS
|
|
|
|
expect(plist).to eq(plist_expect)
|
2020-12-11 23:14:50 +01:00
|
|
|
end
|
|
|
|
|
2022-01-25 19:29:16 +01:00
|
|
|
it "returns valid plist with socket" do
|
2022-08-24 23:52:40 +01:00
|
|
|
f = stub_formula do
|
|
|
|
service do
|
|
|
|
run [opt_bin/"beanstalkd", "test"]
|
|
|
|
sockets "tcp://127.0.0.1:80"
|
|
|
|
end
|
2022-01-25 19:29:16 +01:00
|
|
|
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>
|
2022-07-03 16:25:19 +02:00
|
|
|
\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>
|
2022-01-25 19:29:16 +01:00
|
|
|
\t<key>ProgramArguments</key>
|
|
|
|
\t<array>
|
|
|
|
\t\t<string>#{HOMEBREW_PREFIX}/opt/formula_name/bin/beanstalkd</string>
|
|
|
|
\t\t<string>test</string>
|
|
|
|
\t</array>
|
|
|
|
\t<key>RunAtLoad</key>
|
|
|
|
\t<true/>
|
|
|
|
\t<key>Sockets</key>
|
|
|
|
\t<dict>
|
|
|
|
\t\t<key>Listeners</key>
|
|
|
|
\t\t<dict>
|
|
|
|
\t\t\t<key>SockFamily</key>
|
|
|
|
\t\t\t<string>IPv4v6</string>
|
|
|
|
\t\t\t<key>SockNodeName</key>
|
|
|
|
\t\t\t<string>127.0.0.1</string>
|
|
|
|
\t\t\t<key>SockProtocol</key>
|
|
|
|
\t\t\t<string>TCP</string>
|
|
|
|
\t\t\t<key>SockServiceName</key>
|
|
|
|
\t\t\t<string>80</string>
|
|
|
|
\t\t</dict>
|
|
|
|
\t</dict>
|
|
|
|
</dict>
|
|
|
|
</plist>
|
|
|
|
EOS
|
|
|
|
expect(plist).to eq(plist_expect)
|
|
|
|
end
|
|
|
|
|
2020-12-11 23:14:50 +01:00
|
|
|
it "returns valid partial plist" do
|
2022-08-24 23:52:40 +01:00
|
|
|
f = stub_formula do
|
|
|
|
service do
|
|
|
|
run opt_bin/"beanstalkd"
|
|
|
|
run_type :immediate
|
|
|
|
end
|
2020-12-11 23:14:50 +01:00
|
|
|
end
|
|
|
|
|
2021-04-08 10:06:45 +02:00
|
|
|
plist = f.service.to_plist
|
2021-04-29 09:43:39 +02:00
|
|
|
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>
|
2022-07-03 16:25:19 +02:00
|
|
|
\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>
|
2021-04-29 09:43:39 +02:00
|
|
|
\t<key>ProgramArguments</key>
|
|
|
|
\t<array>
|
|
|
|
\t\t<string>#{HOMEBREW_PREFIX}/opt/formula_name/bin/beanstalkd</string>
|
|
|
|
\t</array>
|
|
|
|
\t<key>RunAtLoad</key>
|
|
|
|
\t<true/>
|
|
|
|
</dict>
|
|
|
|
</plist>
|
|
|
|
EOS
|
|
|
|
expect(plist).to eq(plist_expect)
|
2020-12-11 23:14:50 +01:00
|
|
|
end
|
2021-11-02 17:17:45 +01:00
|
|
|
|
|
|
|
it "returns valid interval plist" do
|
2022-08-24 23:52:40 +01:00
|
|
|
f = stub_formula do
|
|
|
|
service do
|
|
|
|
run opt_bin/"beanstalkd"
|
|
|
|
run_type :interval
|
|
|
|
interval 5
|
|
|
|
end
|
2021-11-02 17:17:45 +01:00
|
|
|
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>
|
2022-07-03 16:25:19 +02:00
|
|
|
\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>
|
2021-11-02 17:17:45 +01:00
|
|
|
\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/>
|
|
|
|
\t<key>StartInterval</key>
|
|
|
|
\t<integer>5</integer>
|
|
|
|
</dict>
|
|
|
|
</plist>
|
|
|
|
EOS
|
|
|
|
expect(plist).to eq(plist_expect)
|
|
|
|
end
|
2021-11-21 14:25:40 +01:00
|
|
|
|
|
|
|
it "returns valid cron plist" do
|
2022-08-24 23:52:40 +01:00
|
|
|
f = stub_formula do
|
|
|
|
service do
|
|
|
|
run opt_bin/"beanstalkd"
|
|
|
|
run_type :cron
|
|
|
|
cron "@daily"
|
|
|
|
end
|
2021-11-21 14:25:40 +01:00
|
|
|
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>
|
2022-07-03 16:25:19 +02:00
|
|
|
\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>
|
2021-11-21 14:25:40 +01:00
|
|
|
\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/>
|
|
|
|
\t<key>StartCalendarInterval</key>
|
|
|
|
\t<dict>
|
|
|
|
\t\t<key>Hour</key>
|
|
|
|
\t\t<integer>0</integer>
|
|
|
|
\t\t<key>Minute</key>
|
|
|
|
\t\t<integer>0</integer>
|
|
|
|
\t</dict>
|
|
|
|
</dict>
|
|
|
|
</plist>
|
|
|
|
EOS
|
|
|
|
expect(plist).to eq(plist_expect)
|
|
|
|
end
|
2022-01-25 19:29:16 +01:00
|
|
|
|
|
|
|
it "returns valid keepalive-exit plist" do
|
2022-08-24 23:52:40 +01:00
|
|
|
f = stub_formula do
|
|
|
|
service do
|
|
|
|
run opt_bin/"beanstalkd"
|
|
|
|
keep_alive successful_exit: false
|
|
|
|
end
|
2022-01-25 19:29:16 +01:00
|
|
|
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>KeepAlive</key>
|
|
|
|
\t<dict>
|
|
|
|
\t\t<key>SuccessfulExit</key>
|
|
|
|
\t\t<false/>
|
|
|
|
\t</dict>
|
|
|
|
\t<key>Label</key>
|
|
|
|
\t<string>homebrew.mxcl.formula_name</string>
|
2022-07-03 16:25:19 +02:00
|
|
|
\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>
|
2022-01-25 19:29:16 +01:00
|
|
|
\t<key>ProgramArguments</key>
|
|
|
|
\t<array>
|
|
|
|
\t\t<string>#{HOMEBREW_PREFIX}/opt/formula_name/bin/beanstalkd</string>
|
|
|
|
\t</array>
|
|
|
|
\t<key>RunAtLoad</key>
|
|
|
|
\t<true/>
|
|
|
|
</dict>
|
|
|
|
</plist>
|
|
|
|
EOS
|
|
|
|
expect(plist).to eq(plist_expect)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns valid keepalive-crashed plist" do
|
2022-08-24 23:52:40 +01:00
|
|
|
f = stub_formula do
|
|
|
|
service do
|
|
|
|
run opt_bin/"beanstalkd"
|
|
|
|
keep_alive crashed: true
|
|
|
|
end
|
2022-01-25 19:29:16 +01:00
|
|
|
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>KeepAlive</key>
|
|
|
|
\t<dict>
|
|
|
|
\t\t<key>Crashed</key>
|
|
|
|
\t\t<true/>
|
|
|
|
\t</dict>
|
|
|
|
\t<key>Label</key>
|
|
|
|
\t<string>homebrew.mxcl.formula_name</string>
|
2022-07-03 16:25:19 +02:00
|
|
|
\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>
|
2022-01-25 19:29:16 +01:00
|
|
|
\t<key>ProgramArguments</key>
|
|
|
|
\t<array>
|
|
|
|
\t\t<string>#{HOMEBREW_PREFIX}/opt/formula_name/bin/beanstalkd</string>
|
|
|
|
\t</array>
|
|
|
|
\t<key>RunAtLoad</key>
|
|
|
|
\t<true/>
|
|
|
|
</dict>
|
|
|
|
</plist>
|
|
|
|
EOS
|
|
|
|
expect(plist).to eq(plist_expect)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns valid keepalive-path plist" do
|
2022-08-24 23:52:40 +01:00
|
|
|
f = stub_formula do
|
|
|
|
service do
|
|
|
|
run opt_bin/"beanstalkd"
|
|
|
|
keep_alive path: opt_pkgshare/"test-path"
|
|
|
|
end
|
2022-01-25 19:29:16 +01:00
|
|
|
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>KeepAlive</key>
|
|
|
|
\t<dict>
|
|
|
|
\t\t<key>PathState</key>
|
|
|
|
\t\t<string>#{HOMEBREW_PREFIX}/opt/formula_name/share/formula_name/test-path</string>
|
|
|
|
\t</dict>
|
|
|
|
\t<key>Label</key>
|
|
|
|
\t<string>homebrew.mxcl.formula_name</string>
|
2022-07-03 16:25:19 +02:00
|
|
|
\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>
|
2022-01-25 19:29:16 +01:00
|
|
|
\t<key>ProgramArguments</key>
|
|
|
|
\t<array>
|
|
|
|
\t\t<string>#{HOMEBREW_PREFIX}/opt/formula_name/bin/beanstalkd</string>
|
|
|
|
\t</array>
|
|
|
|
\t<key>RunAtLoad</key>
|
|
|
|
\t<true/>
|
|
|
|
</dict>
|
|
|
|
</plist>
|
|
|
|
EOS
|
|
|
|
expect(plist).to eq(plist_expect)
|
|
|
|
end
|
2020-12-11 23:14:50 +01:00
|
|
|
end
|
2021-04-13 16:59:59 +02:00
|
|
|
|
|
|
|
describe "#to_systemd_unit" do
|
|
|
|
it "returns valid unit" do
|
2022-08-24 23:52:40 +01:00
|
|
|
f = stub_formula do
|
|
|
|
service do
|
|
|
|
run [opt_bin/"beanstalkd", "test"]
|
|
|
|
run_type :immediate
|
|
|
|
environment_variables PATH: std_service_path_env, FOO: "BAR"
|
|
|
|
error_log_path var/"log/beanstalkd.error.log"
|
|
|
|
log_path var/"log/beanstalkd.log"
|
|
|
|
input_path var/"in/beanstalkd"
|
2022-11-06 13:52:53 +01:00
|
|
|
require_root true
|
2022-08-24 23:52:40 +01:00
|
|
|
root_dir var
|
|
|
|
working_dir var
|
|
|
|
keep_alive true
|
|
|
|
process_type :interactive
|
|
|
|
restart_delay 30
|
|
|
|
macos_legacy_timers true
|
|
|
|
end
|
2021-04-13 16:59:59 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
unit = f.service.to_systemd_unit
|
|
|
|
std_path = "#{HOMEBREW_PREFIX}/bin:#{HOMEBREW_PREFIX}/sbin:/usr/bin:/bin:/usr/sbin:/sbin"
|
2021-04-29 09:43:39 +02:00
|
|
|
unit_expect = <<~EOS
|
|
|
|
[Unit]
|
|
|
|
Description=Homebrew generated unit for formula_name
|
|
|
|
|
2021-06-05 17:59:17 +02:00
|
|
|
[Install]
|
2022-10-07 15:16:58 +02:00
|
|
|
WantedBy=default.target
|
2021-06-05 17:59:17 +02:00
|
|
|
|
2021-04-29 09:43:39 +02:00
|
|
|
[Service]
|
|
|
|
Type=simple
|
|
|
|
ExecStart=#{HOMEBREW_PREFIX}/opt/#{name}/bin/beanstalkd test
|
|
|
|
Restart=always
|
2021-05-22 18:17:36 +02:00
|
|
|
RestartSec=30
|
2021-04-29 09:43:39 +02:00
|
|
|
WorkingDirectory=#{HOMEBREW_PREFIX}/var
|
2021-05-22 18:17:36 +02:00
|
|
|
RootDirectory=#{HOMEBREW_PREFIX}/var
|
|
|
|
StandardInput=file:#{HOMEBREW_PREFIX}/var/in/beanstalkd
|
2021-04-29 09:43:39 +02:00
|
|
|
StandardOutput=append:#{HOMEBREW_PREFIX}/var/log/beanstalkd.log
|
|
|
|
StandardError=append:#{HOMEBREW_PREFIX}/var/log/beanstalkd.error.log
|
|
|
|
Environment=\"PATH=#{std_path}\"
|
2021-05-22 10:59:28 +02:00
|
|
|
Environment=\"FOO=BAR\"
|
2021-04-29 09:43:39 +02:00
|
|
|
EOS
|
|
|
|
expect(unit).to eq(unit_expect.strip)
|
2021-04-13 16:59:59 +02:00
|
|
|
end
|
|
|
|
|
2022-02-11 14:48:05 -06:00
|
|
|
it "returns valid partial oneshot unit" do
|
2022-08-24 23:52:40 +01:00
|
|
|
f = stub_formula do
|
|
|
|
service do
|
|
|
|
run opt_bin/"beanstalkd"
|
|
|
|
run_type :immediate
|
|
|
|
launch_only_once true
|
|
|
|
end
|
2021-04-13 16:59:59 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
unit = f.service.to_systemd_unit
|
2021-04-29 09:43:39 +02:00
|
|
|
unit_expect = <<~EOS
|
|
|
|
[Unit]
|
|
|
|
Description=Homebrew generated unit for formula_name
|
|
|
|
|
2021-06-05 17:59:17 +02:00
|
|
|
[Install]
|
2022-10-07 15:16:58 +02:00
|
|
|
WantedBy=default.target
|
2021-06-05 17:59:17 +02:00
|
|
|
|
2021-04-29 09:43:39 +02:00
|
|
|
[Service]
|
2022-02-11 14:48:05 -06:00
|
|
|
Type=oneshot
|
2021-04-29 09:43:39 +02:00
|
|
|
ExecStart=#{HOMEBREW_PREFIX}/opt/#{name}/bin/beanstalkd
|
|
|
|
EOS
|
2022-02-11 14:48:05 -06:00
|
|
|
expect(unit).to eq(unit_expect.strip)
|
2021-04-13 16:59:59 +02:00
|
|
|
end
|
|
|
|
end
|
2021-04-13 11:25:56 +02:00
|
|
|
|
2021-11-20 15:14:50 +01:00
|
|
|
describe "#to_systemd_timer" do
|
|
|
|
it "returns valid timer" do
|
2022-08-24 23:52:40 +01:00
|
|
|
f = stub_formula do
|
|
|
|
service do
|
|
|
|
run [opt_bin/"beanstalkd", "test"]
|
|
|
|
run_type :interval
|
|
|
|
interval 5
|
|
|
|
end
|
2021-11-20 15:14:50 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
unit = f.service.to_systemd_timer
|
|
|
|
unit_expect = <<~EOS
|
|
|
|
[Unit]
|
|
|
|
Description=Homebrew generated timer for formula_name
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=timers.target
|
|
|
|
|
|
|
|
[Timer]
|
|
|
|
Unit=homebrew.formula_name
|
|
|
|
OnUnitActiveSec=5
|
|
|
|
EOS
|
|
|
|
expect(unit).to eq(unit_expect.strip)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns valid partial timer" do
|
2022-08-24 23:52:40 +01:00
|
|
|
f = stub_formula do
|
|
|
|
service do
|
|
|
|
run opt_bin/"beanstalkd"
|
|
|
|
run_type :immediate
|
|
|
|
end
|
2021-11-20 15:14:50 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
unit = f.service.to_systemd_timer
|
|
|
|
unit_expect = <<~EOS
|
|
|
|
[Unit]
|
|
|
|
Description=Homebrew generated timer for formula_name
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=timers.target
|
|
|
|
|
|
|
|
[Timer]
|
|
|
|
Unit=homebrew.formula_name
|
|
|
|
EOS
|
|
|
|
expect(unit).to eq(unit_expect)
|
|
|
|
end
|
2021-11-21 14:25:40 +01:00
|
|
|
|
|
|
|
it "throws on incomplete cron" do
|
2022-08-24 23:52:40 +01:00
|
|
|
f = stub_formula do
|
|
|
|
service do
|
|
|
|
run opt_bin/"beanstalkd"
|
|
|
|
run_type :cron
|
|
|
|
cron "1 2 3 4"
|
|
|
|
end
|
2021-11-21 14:25:40 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
expect {
|
|
|
|
f.service.to_systemd_timer
|
|
|
|
}.to raise_error TypeError, "Service#parse_cron expects a valid cron syntax"
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns valid cron timers" do
|
|
|
|
styles = {
|
|
|
|
"@hourly": "*-*-*-* *:00:00",
|
|
|
|
"@daily": "*-*-*-* 00:00:00",
|
|
|
|
"@weekly": "0-*-*-* 00:00:00",
|
|
|
|
"@monthly": "*-*-*-1 00:00:00",
|
|
|
|
"@yearly": "*-*-1-1 00:00:00",
|
|
|
|
"@annually": "*-*-1-1 00:00:00",
|
|
|
|
"5 5 5 5 5": "5-*-5-5 05:05:00",
|
|
|
|
}
|
|
|
|
|
|
|
|
styles.each do |cron, calendar|
|
2022-08-24 23:52:40 +01:00
|
|
|
f = stub_formula do
|
|
|
|
service do
|
|
|
|
run opt_bin/"beanstalkd"
|
|
|
|
run_type :cron
|
|
|
|
cron cron.to_s
|
|
|
|
end
|
2021-11-21 14:25:40 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
unit = f.service.to_systemd_timer
|
|
|
|
unit_expect = <<~EOS
|
|
|
|
[Unit]
|
|
|
|
Description=Homebrew generated timer for formula_name
|
|
|
|
|
|
|
|
[Install]
|
|
|
|
WantedBy=timers.target
|
|
|
|
|
|
|
|
[Timer]
|
|
|
|
Unit=homebrew.formula_name
|
|
|
|
Persistent=true
|
|
|
|
OnCalendar=#{calendar}
|
|
|
|
EOS
|
|
|
|
expect(unit).to eq(unit_expect.chomp)
|
|
|
|
end
|
|
|
|
end
|
2021-11-20 15:14:50 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "#timed?" do
|
|
|
|
it "returns false for immediate" do
|
2022-08-24 23:52:40 +01:00
|
|
|
f = stub_formula do
|
|
|
|
service do
|
|
|
|
run [opt_bin/"beanstalkd", "test"]
|
|
|
|
run_type :immediate
|
|
|
|
end
|
2021-11-20 15:14:50 +01:00
|
|
|
end
|
|
|
|
|
2022-03-01 00:02:36 +00:00
|
|
|
expect(f.service.timed?).to be(false)
|
2021-11-20 15:14:50 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns true for interval" do
|
2022-08-24 23:52:40 +01:00
|
|
|
f = stub_formula do
|
|
|
|
service do
|
|
|
|
run [opt_bin/"beanstalkd", "test"]
|
|
|
|
run_type :interval
|
|
|
|
end
|
2021-11-20 15:14:50 +01:00
|
|
|
end
|
|
|
|
|
2022-03-01 00:02:36 +00:00
|
|
|
expect(f.service.timed?).to be(true)
|
2021-11-20 15:14:50 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-03-11 12:42:41 -08:00
|
|
|
describe "#keep_alive?" do
|
2022-01-25 19:29:16 +01:00
|
|
|
it "returns true when keep_alive set to hash" do
|
2022-08-24 23:52:40 +01:00
|
|
|
f = stub_formula do
|
|
|
|
service do
|
|
|
|
run [opt_bin/"beanstalkd", "test"]
|
|
|
|
keep_alive crashed: true
|
|
|
|
end
|
2022-01-25 19:29:16 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
expect(f.service.keep_alive?).to be(true)
|
|
|
|
end
|
|
|
|
|
2022-03-11 12:42:41 -08:00
|
|
|
it "returns true when keep_alive set to true" do
|
2022-08-24 23:52:40 +01:00
|
|
|
f = stub_formula do
|
|
|
|
service do
|
|
|
|
run [opt_bin/"beanstalkd", "test"]
|
|
|
|
keep_alive true
|
|
|
|
end
|
2022-03-11 12:42:41 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
expect(f.service.keep_alive?).to be(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns false when keep_alive not set" do
|
2022-08-24 23:52:40 +01:00
|
|
|
f = stub_formula do
|
|
|
|
service do
|
|
|
|
run [opt_bin/"beanstalkd", "test"]
|
|
|
|
end
|
2022-03-11 12:42:41 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
expect(f.service.keep_alive?).to be(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns false when keep_alive set to false" do
|
2022-08-24 23:52:40 +01:00
|
|
|
f = stub_formula do
|
|
|
|
service do
|
|
|
|
run [opt_bin/"beanstalkd", "test"]
|
|
|
|
keep_alive false
|
|
|
|
end
|
2022-03-11 12:42:41 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
expect(f.service.keep_alive?).to be(false)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-13 11:25:56 +02:00
|
|
|
describe "#command" do
|
|
|
|
it "returns @run data" do
|
2022-08-24 23:52:40 +01:00
|
|
|
f = stub_formula do
|
|
|
|
service do
|
|
|
|
run [opt_bin/"beanstalkd", "test"]
|
|
|
|
run_type :immediate
|
|
|
|
end
|
2021-04-13 11:25:56 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
command = f.service.command
|
2021-04-29 09:43:39 +02:00
|
|
|
expect(command).to eq(["#{HOMEBREW_PREFIX}/opt/#{name}/bin/beanstalkd", "test"])
|
2021-04-13 11:25:56 +02:00
|
|
|
end
|
|
|
|
end
|
2020-12-11 23:14:50 +01:00
|
|
|
end
|