Merge pull request #11428 from SMillerDev/fix/service/env_variables_manual
This commit is contained in:
commit
6f1398a533
@ -155,7 +155,7 @@ class Caveats
|
|||||||
return if !f.plist_manual && !f.service?
|
return if !f.plist_manual && !f.service?
|
||||||
|
|
||||||
command = if f.service?
|
command = if f.service?
|
||||||
f.service.command.join(" ")
|
f.service.manual_command
|
||||||
else
|
else
|
||||||
f.plist_manual
|
f.plist_manual
|
||||||
end
|
end
|
||||||
|
|||||||
@ -172,6 +172,16 @@ module Homebrew
|
|||||||
@run.map(&:to_s)
|
@run.map(&:to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { returns(String) }
|
||||||
|
def manual_command
|
||||||
|
instance_eval(&@service_block)
|
||||||
|
vars = @environment_variables.except(:PATH)
|
||||||
|
.map { |k, v| "#{k}=\"#{v}\"" }
|
||||||
|
|
||||||
|
out = vars + command
|
||||||
|
out.join(" ")
|
||||||
|
end
|
||||||
|
|
||||||
# Returns a `String` plist.
|
# Returns a `String` plist.
|
||||||
# @return [String]
|
# @return [String]
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
@ -216,10 +226,7 @@ module Homebrew
|
|||||||
options << "StandardInput=file:#{@input_path}" if @input_path.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?
|
options += @environment_variables.map { |k, v| "Environment=\"#{k}=#{v}\"" } if @environment_variables.present?
|
||||||
list = @environment_variables.map { |k, v| "#{k}=#{v}" }.join("&")
|
|
||||||
options << "Environment=\"#{list}\""
|
|
||||||
end
|
|
||||||
|
|
||||||
unit + options.join("\n")
|
unit + options.join("\n")
|
||||||
end
|
end
|
||||||
|
|||||||
@ -32,12 +32,44 @@ describe Homebrew::Service do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "#manual_command" do
|
||||||
|
it "returns valid manual_command" do
|
||||||
|
f.class.service do
|
||||||
|
run "#{HOMEBREW_PREFIX}/bin/beanstalkd"
|
||||||
|
run_type :immediate
|
||||||
|
environment_variables PATH: std_service_path_env, ETC_DIR: etc/"beanstalkd"
|
||||||
|
error_log_path var/"log/beanstalkd.error.log"
|
||||||
|
log_path var/"log/beanstalkd.log"
|
||||||
|
working_dir var
|
||||||
|
keep_alive true
|
||||||
|
end
|
||||||
|
|
||||||
|
path = f.service.manual_command
|
||||||
|
expect(path).to eq("ETC_DIR=\"#{HOMEBREW_PREFIX}/etc/beanstalkd\" #{HOMEBREW_PREFIX}/bin/beanstalkd")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns valid manual_command without variables" do
|
||||||
|
f.class.service do
|
||||||
|
run opt_bin/"beanstalkd"
|
||||||
|
run_type :immediate
|
||||||
|
environment_variables PATH: std_service_path_env
|
||||||
|
error_log_path var/"log/beanstalkd.error.log"
|
||||||
|
log_path var/"log/beanstalkd.log"
|
||||||
|
working_dir var
|
||||||
|
keep_alive true
|
||||||
|
end
|
||||||
|
|
||||||
|
path = f.service.manual_command
|
||||||
|
expect(path).to eq("#{HOMEBREW_PREFIX}/opt/formula_name/bin/beanstalkd")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#to_plist" do
|
describe "#to_plist" do
|
||||||
it "returns valid plist" do
|
it "returns valid plist" do
|
||||||
f.class.service do
|
f.class.service do
|
||||||
run [opt_bin/"beanstalkd", "test"]
|
run [opt_bin/"beanstalkd", "test"]
|
||||||
run_type :immediate
|
run_type :immediate
|
||||||
environment_variables PATH: std_service_path_env
|
environment_variables PATH: std_service_path_env, FOO: "BAR"
|
||||||
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"
|
||||||
@ -56,6 +88,8 @@ describe Homebrew::Service do
|
|||||||
<dict>
|
<dict>
|
||||||
\t<key>EnvironmentVariables</key>
|
\t<key>EnvironmentVariables</key>
|
||||||
\t<dict>
|
\t<dict>
|
||||||
|
\t\t<key>FOO</key>
|
||||||
|
\t\t<string>BAR</string>
|
||||||
\t\t<key>PATH</key>
|
\t\t<key>PATH</key>
|
||||||
\t\t<string>#{HOMEBREW_PREFIX}/bin:#{HOMEBREW_PREFIX}/sbin:/usr/bin:/bin:/usr/sbin:/sbin</string>
|
\t\t<string>#{HOMEBREW_PREFIX}/bin:#{HOMEBREW_PREFIX}/sbin:/usr/bin:/bin:/usr/sbin:/sbin</string>
|
||||||
\t</dict>
|
\t</dict>
|
||||||
@ -122,7 +156,7 @@ describe Homebrew::Service do
|
|||||||
f.class.service do
|
f.class.service do
|
||||||
run [opt_bin/"beanstalkd", "test"]
|
run [opt_bin/"beanstalkd", "test"]
|
||||||
run_type :immediate
|
run_type :immediate
|
||||||
environment_variables PATH: std_service_path_env
|
environment_variables PATH: std_service_path_env, FOO: "BAR"
|
||||||
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"
|
||||||
@ -150,6 +184,7 @@ describe Homebrew::Service do
|
|||||||
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}\"
|
||||||
|
Environment=\"FOO=BAR\"
|
||||||
EOS
|
EOS
|
||||||
expect(unit).to eq(unit_expect.strip)
|
expect(unit).to eq(unit_expect.strip)
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user