Updates for configuration generation.
parent
6237a9bb10
commit
2dfcfcb979
|
@ -8,9 +8,9 @@ variables+=(
|
|||
VARSTATEDIR '/var'
|
||||
)
|
||||
|
||||
targets=(service status)
|
||||
targets=(service status get-port)
|
||||
|
||||
for target in service status; do
|
||||
for target in service status get-port; do
|
||||
type[$target]=crystal
|
||||
sources[$target]=src/${target}.cr
|
||||
depends[$target]=src/config.cr
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
require "file_utils"
|
||||
require "./config.cr"
|
||||
|
||||
START_PORT = 49152
|
||||
PORTS_CACHE_DIRECTORY = "#{CACHE_DIRECTORY}/ports/"
|
||||
|
||||
service = ARGV[0]
|
||||
wanted_default_port = ARGV[1]?.try &.to_i
|
||||
|
||||
service_port_file = "#{PORTS_CACHE_DIRECTORY}/#{service}"
|
||||
|
||||
begin
|
||||
if File.exists? service_port_file
|
||||
puts File.read service_port_file
|
||||
exit 0
|
||||
end
|
||||
|
||||
FileUtils.mkdir_p PORTS_CACHE_DIRECTORY
|
||||
|
||||
used_ports = Dir.children(PORTS_CACHE_DIRECTORY)
|
||||
.map { |x| "#{PORTS_CACHE_DIRECTORY}/#{x}" }
|
||||
.map { |x| File.read(x).to_i }
|
||||
.sort
|
||||
|
||||
port = START_PORT
|
||||
if wanted_default_port && ! used_ports.any? &.==(wanted_default_port)
|
||||
port = wanted_default_port
|
||||
else
|
||||
while used_ports.any? &.==(port)
|
||||
port = port + 1
|
||||
end
|
||||
end
|
||||
|
||||
File.write service_port_file, port
|
||||
|
||||
puts port
|
||||
rescue e
|
||||
STDERR.puts "error: #{e.message}"
|
||||
exit 1
|
||||
end
|
||||
|
|
@ -113,9 +113,17 @@ class Service
|
|||
private def build_environment
|
||||
env = {} of String => String
|
||||
|
||||
env["SERVICE_ID"] = id
|
||||
env["ENVIRONMENT"] = @environment.name
|
||||
env["ENVIRONMENT_TYPE"] = @environment.type.to_s
|
||||
|
||||
@providers.each do |token, provider|
|
||||
env["#{token.upcase}_PROVIDER"] = provider
|
||||
env["#{token.upcase}_ENVIRONMENT"] = provider.gsub /\/.*/, ""
|
||||
end
|
||||
|
||||
env["SERVICE_TOKENS"] = @providers.to_a.map(&.[0]).join ':'
|
||||
|
||||
# FIXME: Parsing should probably be done… when parsing the file.
|
||||
# FIXME: Parsing is probably a bit primitive. Maybe this isn’t the right way of defining this.
|
||||
@reference.environment_variables.each do |string|
|
||||
|
@ -164,7 +172,7 @@ class Service
|
|||
puts " - #{check.name}"
|
||||
|
||||
child = Process.fork do
|
||||
Process.exec "sh", ["-c", evaluate check.command],
|
||||
Process.exec "sh", ["-c", check.command],
|
||||
output: Process::Redirect::Inherit,
|
||||
error: Process::Redirect::Inherit,
|
||||
env: build_environment
|
||||
|
@ -196,7 +204,7 @@ class Service
|
|||
end
|
||||
|
||||
Process.exec command, args,
|
||||
chdir: @reference.directory,
|
||||
chdir: @reference.directory.try { |x| evaluate x },
|
||||
env: build_environment
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue