service add-environment <name>, bugfixes.

master
Luka Vandervelden 2019-10-24 18:29:22 +02:00
parent c6dd306361
commit de2b124d09
3 changed files with 22 additions and 10 deletions

View File

@ -165,6 +165,8 @@ begin
Service.all.map do |service|
puts service.to_s
end
elsif args[0] == "add-environment"
Environment.new(args[1]).write ENVIRONMENTS_DIRECTORY
elsif args[0] == "list-environments"
Environment.all.map do |env|
puts env.to_s

View File

@ -12,7 +12,12 @@ class Environment
getter checks = Array(ServiceDefinition::Checks).new
def initialize()
@name = "root"
initialize "root"
end
def initialize(@name, type = "prefix")
@type = Type.parse type
@checks = Array(ServiceDefinition::Checks).new
# FIXME: Should this *really* be here?
@ -59,6 +64,17 @@ class Environment
end
end
def write(dir : String)
File.write "#{dir}/#{@name}.spec", to_spec
end
def to_spec
[
"name: #{@name}",
"type: #{@type.to_s}"
].join("\n") + "\n"
end
def self.get(name)
_def = @@all.find &.name.==(name)

View File

@ -238,7 +238,7 @@ class Service
end
def get_pid_file(pid_dir)
"#{pid_dir}/#{name}.pid"
"#{pid_dir}/#{name}.#{environment.name}.pid"
end
def pid(pid_dir)
@ -342,16 +342,10 @@ class Service
unless matches # Should not happen, above regex would always match.
raise Exception.new "FIXME"
end
environment_name = matches[0]
service_name = if environment_name == id
environment_name = "root"
id
else
id.sub 0..matches[0].size, ""
end
environment_name, service_name = Service.parse_id id
@@all.find do |service|
service.name == service_name
service.name == service_name && service.environment.name == environment_name
end
end
def is_id?(id)