Service definitions get some sugar.

- %configuration template target
  - %directory target
  - Services are started in their “root directory” if no “directory”
    option is provided.
This commit is contained in:
Luka Vandervelden 2019-10-26 15:24:22 +02:00
parent 7b02cffb9e
commit f53db2c6cc
3 changed files with 40 additions and 21 deletions

View File

@ -1,25 +1,10 @@
command: ./gitea -C . -w . -c ./custom/conf/app.ini
# deamon's working directory
directory: ${SERVICE_ROOT} # FIXME: Could this be removed?
command: gitea -C . -w . -c ./custom/conf/app.ini
consumes: postgresql
%pre-start
name: working directory
# 'command' is run only if this directory doesn't exist
unless-directory: ${SERVICE_ROOT}/custom/conf/
command: mkdir -p ${SERVICE_ROOT}/custom/conf/
%directory ${SERVICE_ROOT}/custom/conf
name: working directory
%pre-start
name: symlink
# 'command' is run only if this directory doesn't exist
unless-file: ${SERVICE_ROOT}/gitea
command: ln -s $(which gitea) ${SERVICE_ROOT}/gitea
%pre-start
name: configuration file
# 'command' is run only if this file doesn't exist
unless-file: ${SERVICE_ROOT}/custom/conf/app.ini
command: gen-config gitea.cfg ${SERVICE_ROOT}/custom/conf/app.ini postgresql=${POSTGRESQL_PROVIDER}
%configuration gitea.cfg ${SERVICE_ROOT}/custom/conf/app.ini
%pre-start
name: gitea database creation

View File

@ -236,7 +236,7 @@ class Service
end
Process.exec command, args,
chdir: @reference.directory.try { |x| evaluate x },
chdir: (@reference.directory.try { |x| evaluate x } || root),
env: build_environment
end

View File

@ -60,7 +60,41 @@ class ServiceDefinition
@consumes = specs["consumes"]?.try &.as_a_or_s.map { |x| Consumes.new x } || Array(Consumes).new
@environment_variables = specs["environment-variables"]?.try &.as_a_or_s || Array(String).new
@pre_start_hooks = sections.select(&.name.== "pre-start").map { |x| Hook.new x } || Array(Hook).new
@pre_start_hooks = Array(Hook).new
sections.each do |section|
case section.name
when "pre-start"
@pre_start_hooks << Hook.new section
when "directory"
directory = section.options[0]?
name = section.content["name"]?.try &.as_s
if directory.nil?
STDERR.puts "warning: (#{@name}) %directory was not provided a path"
next
end
pre_start_hooks << Hook.new (name || "directory: #{directory}"),
"mkdir -p \"#{directory}\"",
unless_directory: directory
when "configuration"
options = section.options[0].split /[ \t]/
template = options[0]?
target = options[1]?
name = section.content["name"]?.try &.as_s
if template.nil? || target.nil?
STDERR.puts "warning: (#{@name}) %configuration received less than 2 options"
next
end
pre_start_hooks << Hook.new (name || "configuration file: #{template}"),
"gen-config \"#{template}\" \"#{target}\"",
unless_file: target
end
end
end
def self.load(path)