Merge pull request #11316 from SMillerDev/feature/linux/write_unit
This commit is contained in:
commit
42ffee75a1
@ -962,12 +962,24 @@ class Formula
|
|||||||
"homebrew.mxcl.#{name}"
|
"homebrew.mxcl.#{name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# The generated service name.
|
||||||
|
sig { returns(String) }
|
||||||
|
def service_name
|
||||||
|
"homebrew.#{name}"
|
||||||
|
end
|
||||||
|
|
||||||
# The generated launchd {.plist} file path.
|
# The generated launchd {.plist} file path.
|
||||||
sig { returns(Pathname) }
|
sig { returns(Pathname) }
|
||||||
def plist_path
|
def plist_path
|
||||||
prefix/"#{plist_name}.plist"
|
prefix/"#{plist_name}.plist"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# The generated systemd {.service} file path.
|
||||||
|
sig { returns(Pathname) }
|
||||||
|
def systemd_service_path
|
||||||
|
prefix/"#{service_name}.service"
|
||||||
|
end
|
||||||
|
|
||||||
# The service specification of the software.
|
# The service specification of the software.
|
||||||
def service
|
def service
|
||||||
return unless service?
|
return unless service?
|
||||||
|
@ -1020,21 +1020,27 @@ class FormulaInstaller
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
plist = if formula.service?
|
if formula.service?
|
||||||
|
service_path = formula.systemd_service_path
|
||||||
|
service_path.atomic_write(formula.service.to_systemd_unit)
|
||||||
|
service_path.chmod 0644
|
||||||
|
end
|
||||||
|
|
||||||
|
service = if formula.service?
|
||||||
formula.service.to_plist
|
formula.service.to_plist
|
||||||
elsif formula.plist
|
elsif formula.plist
|
||||||
formula.plist
|
formula.plist
|
||||||
end
|
end
|
||||||
|
|
||||||
return unless plist
|
return unless service
|
||||||
|
|
||||||
plist_path = formula.plist_path
|
plist_path = formula.plist_path
|
||||||
plist_path.atomic_write(plist)
|
plist_path.atomic_write(service)
|
||||||
plist_path.chmod 0644
|
plist_path.chmod 0644
|
||||||
log = formula.var/"log"
|
log = formula.var/"log"
|
||||||
log.mkpath if plist.include? log.to_s
|
log.mkpath if service.include? log.to_s
|
||||||
rescue Exception => e # rubocop:disable Lint/RescueException
|
rescue Exception => e # rubocop:disable Lint/RescueException
|
||||||
ofail "Failed to install plist file"
|
ofail "Failed to install service files"
|
||||||
odebug e, e.backtrace
|
odebug e, e.backtrace
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -231,30 +231,34 @@ describe FormulaInstaller do
|
|||||||
installer = described_class.new(formula)
|
installer = described_class.new(formula)
|
||||||
expect {
|
expect {
|
||||||
installer.install_service
|
installer.install_service
|
||||||
}.not_to output(/Error: Failed to install plist file/).to_stderr
|
}.not_to output(/Error: Failed to install service files/).to_stderr
|
||||||
|
|
||||||
expect(path).to exist
|
expect(path).to exist
|
||||||
end
|
end
|
||||||
|
|
||||||
it "works if service is set" do
|
it "works if service is set" do
|
||||||
formula = Testball.new
|
formula = Testball.new
|
||||||
path = formula.plist_path
|
plist_path = formula.plist_path
|
||||||
|
service_path = formula.systemd_service_path
|
||||||
service = Homebrew::Service.new(formula)
|
service = Homebrew::Service.new(formula)
|
||||||
formula.prefix.mkpath
|
formula.prefix.mkpath
|
||||||
|
|
||||||
expect(formula).to receive(:plist).and_return(nil)
|
expect(formula).to receive(:plist).and_return(nil)
|
||||||
expect(formula).to receive(:service?).twice.and_return(true)
|
expect(formula).to receive(:service?).exactly(3).and_return(true)
|
||||||
expect(formula).to receive(:service).and_return(service)
|
expect(formula).to receive(:service).twice.and_return(service)
|
||||||
expect(formula).to receive(:plist_path).and_call_original
|
expect(formula).to receive(:plist_path).and_call_original
|
||||||
|
expect(formula).to receive(:systemd_service_path).and_call_original
|
||||||
|
|
||||||
expect(service).to receive(:to_plist).and_return("plist")
|
expect(service).to receive(:to_plist).and_return("plist")
|
||||||
|
expect(service).to receive(:to_systemd_unit).and_return("unit")
|
||||||
|
|
||||||
installer = described_class.new(formula)
|
installer = described_class.new(formula)
|
||||||
expect {
|
expect {
|
||||||
installer.install_service
|
installer.install_service
|
||||||
}.not_to output(/Error: Failed to install plist file/).to_stderr
|
}.not_to output(/Error: Failed to install service files/).to_stderr
|
||||||
|
|
||||||
expect(path).to exist
|
expect(plist_path).to exist
|
||||||
|
expect(service_path).to exist
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns without definition" do
|
it "returns without definition" do
|
||||||
@ -263,13 +267,14 @@ describe FormulaInstaller do
|
|||||||
formula.prefix.mkpath
|
formula.prefix.mkpath
|
||||||
|
|
||||||
expect(formula).to receive(:plist).and_return(nil)
|
expect(formula).to receive(:plist).and_return(nil)
|
||||||
expect(formula).to receive(:service?).twice.and_return(nil)
|
expect(formula).to receive(:service?).exactly(3).and_return(nil)
|
||||||
expect(formula).not_to receive(:plist_path)
|
expect(formula).not_to receive(:plist_path)
|
||||||
|
expect(formula).not_to receive(:to_systemd_unit)
|
||||||
|
|
||||||
installer = described_class.new(formula)
|
installer = described_class.new(formula)
|
||||||
expect {
|
expect {
|
||||||
installer.install_service
|
installer.install_service
|
||||||
}.not_to output(/Error: Failed to install plist file/).to_stderr
|
}.not_to output(/Error: Failed to install service files/).to_stderr
|
||||||
|
|
||||||
expect(path).not_to exist
|
expect(path).not_to exist
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user