Merge pull request #14113 from SMillerDev/feature/service/require_root
Service: add method to define a root requirement
This commit is contained in:
commit
133c639ba9
@ -995,6 +995,8 @@ class Formula
|
|||||||
# </plist>
|
# </plist>
|
||||||
# EOS
|
# EOS
|
||||||
# end</pre>
|
# end</pre>
|
||||||
|
#
|
||||||
|
# @deprecated Please use {#service} instead
|
||||||
def plist
|
def plist
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
@ -1014,6 +1016,14 @@ class Formula
|
|||||||
# The generated launchd {.plist} file path.
|
# The generated launchd {.plist} file path.
|
||||||
sig { returns(Pathname) }
|
sig { returns(Pathname) }
|
||||||
def plist_path
|
def plist_path
|
||||||
|
# TODO: Add deprecation
|
||||||
|
# odeprecated "formula.plist_path", "formula.launchd_service_path"
|
||||||
|
launchd_service_path
|
||||||
|
end
|
||||||
|
|
||||||
|
# The generated systemd {.service} file path.
|
||||||
|
sig { returns(Pathname) }
|
||||||
|
def launchd_service_path
|
||||||
opt_prefix/"#{plist_name}.plist"
|
opt_prefix/"#{plist_name}.plist"
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -3121,7 +3131,11 @@ class Formula
|
|||||||
#
|
#
|
||||||
# Or perhaps you'd like to give the user a choice? Ooh fancy.
|
# Or perhaps you'd like to give the user a choice? Ooh fancy.
|
||||||
# <pre>plist_options startup: true, manual: "foo start"</pre>
|
# <pre>plist_options startup: true, manual: "foo start"</pre>
|
||||||
|
#
|
||||||
|
# @deprecated Please use {#service.require_root} instead
|
||||||
def plist_options(options)
|
def plist_options(options)
|
||||||
|
# TODO: Deprecate
|
||||||
|
# odeprecated "plist_options", "service.require_root"
|
||||||
@plist_startup = options[:startup]
|
@plist_startup = options[:startup]
|
||||||
@plist_manual = options[:manual]
|
@plist_manual = options[:manual]
|
||||||
end
|
end
|
||||||
@ -3259,7 +3273,7 @@ class Formula
|
|||||||
# Service can be used to define services.
|
# Service can be used to define services.
|
||||||
# This method evaluates the DSL specified in the service block of the
|
# This method evaluates the DSL specified in the service block of the
|
||||||
# {Formula} (if it exists) and sets the instance variables of a Service
|
# {Formula} (if it exists) and sets the instance variables of a Service
|
||||||
# object accordingly. This is used by `brew install` to generate a plist.
|
# object accordingly. This is used by `brew install` to generate a service file.
|
||||||
#
|
#
|
||||||
# <pre>service do
|
# <pre>service do
|
||||||
# run [opt_bin/"foo"]
|
# run [opt_bin/"foo"]
|
||||||
|
|||||||
@ -129,6 +129,26 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(value: T.nilable(T::Boolean)).returns(T.nilable(T::Boolean)) }
|
||||||
|
def require_root(value = nil)
|
||||||
|
case T.unsafe(value)
|
||||||
|
when nil
|
||||||
|
@require_root
|
||||||
|
when true, false
|
||||||
|
@require_root = value
|
||||||
|
else
|
||||||
|
raise TypeError, "Service#require_root expects a Boolean"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns a `Boolean` describing if a service requires root access.
|
||||||
|
# @return [Boolean]
|
||||||
|
sig { returns(T::Boolean) }
|
||||||
|
def requires_root?
|
||||||
|
instance_eval(&@service_block)
|
||||||
|
@require_root.present? && @require_root == true
|
||||||
|
end
|
||||||
|
|
||||||
sig { params(value: T.nilable(String)).returns(T.nilable(T::Hash[Symbol, String])) }
|
sig { params(value: T.nilable(String)).returns(T.nilable(T::Hash[Symbol, String])) }
|
||||||
def sockets(value = nil)
|
def sockets(value = nil)
|
||||||
case T.unsafe(value)
|
case T.unsafe(value)
|
||||||
|
|||||||
@ -733,7 +733,7 @@ describe Formula do
|
|||||||
|
|
||||||
expect(f.plist_name).to eq("homebrew.mxcl.formula_name")
|
expect(f.plist_name).to eq("homebrew.mxcl.formula_name")
|
||||||
expect(f.service_name).to eq("homebrew.formula_name")
|
expect(f.service_name).to eq("homebrew.formula_name")
|
||||||
expect(f.plist_path).to eq(HOMEBREW_PREFIX/"opt/formula_name/homebrew.mxcl.formula_name.plist")
|
expect(f.launchd_service_path).to eq(HOMEBREW_PREFIX/"opt/formula_name/homebrew.mxcl.formula_name.plist")
|
||||||
expect(f.systemd_service_path).to eq(HOMEBREW_PREFIX/"opt/formula_name/homebrew.formula_name.service")
|
expect(f.systemd_service_path).to eq(HOMEBREW_PREFIX/"opt/formula_name/homebrew.formula_name.service")
|
||||||
expect(f.systemd_timer_path).to eq(HOMEBREW_PREFIX/"opt/formula_name/homebrew.formula_name.timer")
|
expect(f.systemd_timer_path).to eq(HOMEBREW_PREFIX/"opt/formula_name/homebrew.formula_name.timer")
|
||||||
end
|
end
|
||||||
|
|||||||
@ -64,6 +64,29 @@ describe Homebrew::Service do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
describe "#run_type" do
|
describe "#run_type" do
|
||||||
it "throws for unexpected type" do
|
it "throws for unexpected type" do
|
||||||
f = stub_formula do
|
f = stub_formula do
|
||||||
@ -166,6 +189,7 @@ describe Homebrew::Service do
|
|||||||
error_log_path var/"log/beanstalkd.error.log"
|
error_log_path var/"log/beanstalkd.error.log"
|
||||||
log_path var/"log/beanstalkd.log"
|
log_path var/"log/beanstalkd.log"
|
||||||
input_path var/"in/beanstalkd"
|
input_path var/"in/beanstalkd"
|
||||||
|
require_root true
|
||||||
root_dir var
|
root_dir var
|
||||||
working_dir var
|
working_dir var
|
||||||
keep_alive true
|
keep_alive true
|
||||||
@ -539,6 +563,7 @@ describe Homebrew::Service do
|
|||||||
error_log_path var/"log/beanstalkd.error.log"
|
error_log_path var/"log/beanstalkd.error.log"
|
||||||
log_path var/"log/beanstalkd.log"
|
log_path var/"log/beanstalkd.log"
|
||||||
input_path var/"in/beanstalkd"
|
input_path var/"in/beanstalkd"
|
||||||
|
require_root true
|
||||||
root_dir var
|
root_dir var
|
||||||
working_dir var
|
working_dir var
|
||||||
keep_alive true
|
keep_alive true
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user