diff --git a/Library/Homebrew/service.rb b/Library/Homebrew/service.rb
index cec0e9e546..1447935bfd 100644
--- a/Library/Homebrew/service.rb
+++ b/Library/Homebrew/service.rb
@@ -47,6 +47,30 @@ module Homebrew
end
end
+ sig { params(path: T.nilable(T.any(String, Pathname))).returns(T.nilable(String)) }
+ def root_dir(path = nil)
+ case T.unsafe(path)
+ when nil
+ @root_dir
+ when String, Pathname
+ @root_dir = path.to_s
+ else
+ raise TypeError, "Service#root_dir expects a String"
+ end
+ end
+
+ sig { params(path: T.nilable(T.any(String, Pathname))).returns(T.nilable(String)) }
+ def input_path(path = nil)
+ case T.unsafe(path)
+ when nil
+ @input_path
+ when String, Pathname
+ @input_path = path.to_s
+ else
+ raise TypeError, "Service#input_path expects a String"
+ end
+ end
+
sig { params(path: T.nilable(T.any(String, Pathname))).returns(T.nilable(String)) }
def log_path(path = nil)
case T.unsafe(path)
@@ -83,6 +107,18 @@ module Homebrew
end
end
+ sig { params(value: T.nilable(Integer)).returns(T.nilable(Integer)) }
+ def restart_delay(value = nil)
+ case T.unsafe(value)
+ when nil
+ @restart_delay
+ when Integer
+ @restart_delay = value
+ else
+ raise TypeError, "Service#restart_delay expects an Integer"
+ end
+ end
+
sig { params(type: T.nilable(T.any(String, Symbol))).returns(T.nilable(String)) }
def run_type(type = nil)
case T.unsafe(type)
@@ -111,6 +147,18 @@ module Homebrew
end
end
+ sig { params(value: T.nilable(T::Boolean)).returns(T.nilable(T::Boolean)) }
+ def macos_legacy_timers(value = nil)
+ case T.unsafe(value)
+ when nil
+ @macos_legacy_timers
+ when true, false
+ @macos_legacy_timers = value
+ else
+ raise TypeError, "Service#macos_legacy_timers expects a Boolean"
+ end
+ end
+
delegate [:bin, :etc, :libexec, :opt_bin, :opt_libexec, :opt_pkgshare, :opt_prefix, :opt_sbin, :var] => :@formula
sig { returns(String) }
@@ -135,7 +183,11 @@ module Homebrew
}
base[:KeepAlive] = @keep_alive if @keep_alive == true
+ base[:LegacyTimers] = @macos_legacy_timers if @macos_legacy_timers == true
+ base[:TimeOut] = @restart_delay if @restart_delay.present?
base[:WorkingDirectory] = @working_dir if @working_dir.present?
+ base[:RootDirectory] = @root_dir if @root_dir.present?
+ base[:StandardInPath] = @input_path if @input_path.present?
base[:StandardOutPath] = @log_path if @log_path.present?
base[:StandardErrorPath] = @error_log_path if @error_log_path.present?
base[:EnvironmentVariables] = @environment_variables unless @environment_variables.empty?
@@ -158,7 +210,10 @@ module Homebrew
options = []
options << "Restart=always" if @keep_alive == true
+ options << "RestartSec=#{restart_delay}" if @restart_delay.present?
options << "WorkingDirectory=#{@working_dir}" if @working_dir.present?
+ options << "RootDirectory=#{@root_dir}" if @root_dir.present?
+ options << "StandardInput=file:#{@input_path}" if @input_path.present?
options << "StandardOutput=append:#{@log_path}" if @log_path.present?
options << "StandardError=append:#{@error_log_path}" if @error_log_path.present?
if @environment_variables.present?
diff --git a/Library/Homebrew/test/service_spec.rb b/Library/Homebrew/test/service_spec.rb
index 2c7bd94428..09eacbf2eb 100644
--- a/Library/Homebrew/test/service_spec.rb
+++ b/Library/Homebrew/test/service_spec.rb
@@ -40,8 +40,12 @@ describe Homebrew::Service do
environment_variables PATH: std_service_path_env
error_log_path var/"log/beanstalkd.error.log"
log_path var/"log/beanstalkd.log"
+ input_path var/"in/beanstalkd"
+ root_dir var
working_dir var
keep_alive true
+ restart_delay 30
+ macos_legacy_timers true
end
plist = f.service.to_plist
@@ -59,17 +63,25 @@ describe Homebrew::Service do
\t
\tLabel
\thomebrew.mxcl.formula_name
+ \tLegacyTimers
+ \t
\tProgramArguments
\t
\t\t#{HOMEBREW_PREFIX}/opt/formula_name/bin/beanstalkd
\t\ttest
\t
+ \tRootDirectory
+ \t#{HOMEBREW_PREFIX}/var
\tRunAtLoad
\t
\tStandardErrorPath
\t#{HOMEBREW_PREFIX}/var/log/beanstalkd.error.log
+ \tStandardInPath
+ \t#{HOMEBREW_PREFIX}/var/in/beanstalkd
\tStandardOutPath
\t#{HOMEBREW_PREFIX}/var/log/beanstalkd.log
+ \tTimeOut
+ \t30
\tWorkingDirectory
\t#{HOMEBREW_PREFIX}/var
@@ -113,8 +125,12 @@ describe Homebrew::Service do
environment_variables PATH: std_service_path_env
error_log_path var/"log/beanstalkd.error.log"
log_path var/"log/beanstalkd.log"
+ input_path var/"in/beanstalkd"
+ root_dir var
working_dir var
keep_alive true
+ restart_delay 30
+ macos_legacy_timers true
end
unit = f.service.to_systemd_unit
@@ -127,7 +143,10 @@ describe Homebrew::Service do
Type=simple
ExecStart=#{HOMEBREW_PREFIX}/opt/#{name}/bin/beanstalkd test
Restart=always
+ RestartSec=30
WorkingDirectory=#{HOMEBREW_PREFIX}/var
+ RootDirectory=#{HOMEBREW_PREFIX}/var
+ StandardInput=file:#{HOMEBREW_PREFIX}/var/in/beanstalkd
StandardOutput=append:#{HOMEBREW_PREFIX}/var/log/beanstalkd.log
StandardError=append:#{HOMEBREW_PREFIX}/var/log/beanstalkd.error.log
Environment=\"PATH=#{std_path}\"