diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 11dd02b689..5f1dc628fb 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -995,6 +995,8 @@ class Formula # # EOS # end + # + # @deprecated Please use {#service} instead def plist nil end @@ -1014,6 +1016,14 @@ class Formula # The generated launchd {.plist} file path. sig { returns(Pathname) } 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" end @@ -3121,7 +3131,11 @@ class Formula # # Or perhaps you'd like to give the user a choice? Ooh fancy. #
plist_options startup: true, manual: "foo start"
+ # + # @deprecated Please use {#service.require_root} instead def plist_options(options) + # TODO: Deprecate + # odeprecated "plist_options", "service.require_root" @plist_startup = options[:startup] @plist_manual = options[:manual] end @@ -3259,7 +3273,7 @@ class Formula # Service can be used to define services. # This method evaluates the DSL specified in the service block of the # {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. # #
service do
     #   run [opt_bin/"foo"]
diff --git a/Library/Homebrew/service.rb b/Library/Homebrew/service.rb
index 50e5652604..31d6d21100 100644
--- a/Library/Homebrew/service.rb
+++ b/Library/Homebrew/service.rb
@@ -129,6 +129,26 @@ module Homebrew
       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])) }
     def sockets(value = nil)
       case T.unsafe(value)
diff --git a/Library/Homebrew/test/formula_spec.rb b/Library/Homebrew/test/formula_spec.rb
index 6c8a74c93c..0c7b2ee5d9 100644
--- a/Library/Homebrew/test/formula_spec.rb
+++ b/Library/Homebrew/test/formula_spec.rb
@@ -733,7 +733,7 @@ describe Formula do
 
       expect(f.plist_name).to eq("homebrew.mxcl.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_timer_path).to eq(HOMEBREW_PREFIX/"opt/formula_name/homebrew.formula_name.timer")
     end
diff --git a/Library/Homebrew/test/service_spec.rb b/Library/Homebrew/test/service_spec.rb
index f5c68d3c85..b55df5b32b 100644
--- a/Library/Homebrew/test/service_spec.rb
+++ b/Library/Homebrew/test/service_spec.rb
@@ -64,6 +64,29 @@ describe Homebrew::Service do
     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
     it "throws for unexpected type" do
       f = stub_formula do
@@ -166,6 +189,7 @@ describe Homebrew::Service do
           error_log_path var/"log/beanstalkd.error.log"
           log_path var/"log/beanstalkd.log"
           input_path var/"in/beanstalkd"
+          require_root true
           root_dir var
           working_dir var
           keep_alive true
@@ -539,6 +563,7 @@ describe Homebrew::Service do
           error_log_path var/"log/beanstalkd.error.log"
           log_path var/"log/beanstalkd.log"
           input_path var/"in/beanstalkd"
+          require_root true
           root_dir var
           working_dir var
           keep_alive true