Skip to content
Snippets Groups Projects
Unverified Commit fceaa2bb authored by Sean Molenaar's avatar Sean Molenaar
Browse files

Service: add additional options

parent 23bc81cd
No related branches found
No related tags found
No related merge requests found
......@@ -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?
......
......@@ -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<true/>
\t<key>Label</key>
\t<string>homebrew.mxcl.formula_name</string>
\t<key>LegacyTimers</key>
\t<true/>
\t<key>ProgramArguments</key>
\t<array>
\t\t<string>#{HOMEBREW_PREFIX}/opt/formula_name/bin/beanstalkd</string>
\t\t<string>test</string>
\t</array>
\t<key>RootDirectory</key>
\t<string>#{HOMEBREW_PREFIX}/var</string>
\t<key>RunAtLoad</key>
\t<true/>
\t<key>StandardErrorPath</key>
\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<string>#{HOMEBREW_PREFIX}/var/log/beanstalkd.log</string>
\t<key>TimeOut</key>
\t<integer>30</integer>
\t<key>WorkingDirectory</key>
\t<string>#{HOMEBREW_PREFIX}/var</string>
</dict>
......@@ -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}\"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment