Merge pull request #11430 from SMillerDev/feature/service/additional_options

Service: add additional options
This commit is contained in:
Sean Molenaar 2021-05-25 09:29:19 +02:00 committed by GitHub
commit 1bdfacddc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 74 additions and 0 deletions

View File

@ -47,6 +47,30 @@ module Homebrew
end end
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 or Pathname"
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 or Pathname"
end
end
sig { params(path: T.nilable(T.any(String, Pathname))).returns(T.nilable(String)) } sig { params(path: T.nilable(T.any(String, Pathname))).returns(T.nilable(String)) }
def log_path(path = nil) def log_path(path = nil)
case T.unsafe(path) case T.unsafe(path)
@ -83,6 +107,18 @@ module Homebrew
end end
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)) } sig { params(type: T.nilable(T.any(String, Symbol))).returns(T.nilable(String)) }
def run_type(type = nil) def run_type(type = nil)
case T.unsafe(type) case T.unsafe(type)
@ -111,6 +147,18 @@ module Homebrew
end end
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 delegate [:bin, :etc, :libexec, :opt_bin, :opt_libexec, :opt_pkgshare, :opt_prefix, :opt_sbin, :var] => :@formula
sig { returns(String) } sig { returns(String) }
@ -135,7 +183,11 @@ module Homebrew
} }
base[:KeepAlive] = @keep_alive if @keep_alive == true 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[: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[:StandardOutPath] = @log_path if @log_path.present?
base[:StandardErrorPath] = @error_log_path if @error_log_path.present? base[:StandardErrorPath] = @error_log_path if @error_log_path.present?
base[:EnvironmentVariables] = @environment_variables unless @environment_variables.empty? base[:EnvironmentVariables] = @environment_variables unless @environment_variables.empty?
@ -158,7 +210,10 @@ module Homebrew
options = [] options = []
options << "Restart=always" if @keep_alive == true options << "Restart=always" if @keep_alive == true
options << "RestartSec=#{restart_delay}" if @restart_delay.present?
options << "WorkingDirectory=#{@working_dir}" if @working_dir.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 << "StandardOutput=append:#{@log_path}" if @log_path.present?
options << "StandardError=append:#{@error_log_path}" if @error_log_path.present? options << "StandardError=append:#{@error_log_path}" if @error_log_path.present?
if @environment_variables.present? if @environment_variables.present?

View File

@ -40,8 +40,12 @@ describe Homebrew::Service do
environment_variables PATH: std_service_path_env environment_variables PATH: std_service_path_env
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"
root_dir var
working_dir var working_dir var
keep_alive true keep_alive true
restart_delay 30
macos_legacy_timers true
end end
plist = f.service.to_plist plist = f.service.to_plist
@ -59,17 +63,25 @@ describe Homebrew::Service do
\t<true/> \t<true/>
\t<key>Label</key> \t<key>Label</key>
\t<string>homebrew.mxcl.formula_name</string> \t<string>homebrew.mxcl.formula_name</string>
\t<key>LegacyTimers</key>
\t<true/>
\t<key>ProgramArguments</key> \t<key>ProgramArguments</key>
\t<array> \t<array>
\t\t<string>#{HOMEBREW_PREFIX}/opt/formula_name/bin/beanstalkd</string> \t\t<string>#{HOMEBREW_PREFIX}/opt/formula_name/bin/beanstalkd</string>
\t\t<string>test</string> \t\t<string>test</string>
\t</array> \t</array>
\t<key>RootDirectory</key>
\t<string>#{HOMEBREW_PREFIX}/var</string>
\t<key>RunAtLoad</key> \t<key>RunAtLoad</key>
\t<true/> \t<true/>
\t<key>StandardErrorPath</key> \t<key>StandardErrorPath</key>
\t<string>#{HOMEBREW_PREFIX}/var/log/beanstalkd.error.log</string> \t<string>#{HOMEBREW_PREFIX}/var/log/beanstalkd.error.log</string>
\t<key>StandardInPath</key>
\t<string>#{HOMEBREW_PREFIX}/var/in/beanstalkd</string>
\t<key>StandardOutPath</key> \t<key>StandardOutPath</key>
\t<string>#{HOMEBREW_PREFIX}/var/log/beanstalkd.log</string> \t<string>#{HOMEBREW_PREFIX}/var/log/beanstalkd.log</string>
\t<key>TimeOut</key>
\t<integer>30</integer>
\t<key>WorkingDirectory</key> \t<key>WorkingDirectory</key>
\t<string>#{HOMEBREW_PREFIX}/var</string> \t<string>#{HOMEBREW_PREFIX}/var</string>
</dict> </dict>
@ -113,8 +125,12 @@ describe Homebrew::Service do
environment_variables PATH: std_service_path_env environment_variables PATH: std_service_path_env
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"
root_dir var
working_dir var working_dir var
keep_alive true keep_alive true
restart_delay 30
macos_legacy_timers true
end end
unit = f.service.to_systemd_unit unit = f.service.to_systemd_unit
@ -127,7 +143,10 @@ describe Homebrew::Service do
Type=simple Type=simple
ExecStart=#{HOMEBREW_PREFIX}/opt/#{name}/bin/beanstalkd test ExecStart=#{HOMEBREW_PREFIX}/opt/#{name}/bin/beanstalkd test
Restart=always Restart=always
RestartSec=30
WorkingDirectory=#{HOMEBREW_PREFIX}/var WorkingDirectory=#{HOMEBREW_PREFIX}/var
RootDirectory=#{HOMEBREW_PREFIX}/var
StandardInput=file:#{HOMEBREW_PREFIX}/var/in/beanstalkd
StandardOutput=append:#{HOMEBREW_PREFIX}/var/log/beanstalkd.log StandardOutput=append:#{HOMEBREW_PREFIX}/var/log/beanstalkd.log
StandardError=append:#{HOMEBREW_PREFIX}/var/log/beanstalkd.error.log StandardError=append:#{HOMEBREW_PREFIX}/var/log/beanstalkd.error.log
Environment=\"PATH=#{std_path}\" Environment=\"PATH=#{std_path}\"