Service definitions get some sugar.
- %configuration template target - %directory target - Services are started in their “root directory” if no “directory” option is provided.master
parent
7b02cffb9e
commit
f53db2c6cc
|
@ -1,25 +1,10 @@
|
||||||
command: ./gitea -C . -w . -c ./custom/conf/app.ini
|
command: gitea -C . -w . -c ./custom/conf/app.ini
|
||||||
# deamon's working directory
|
|
||||||
directory: ${SERVICE_ROOT} # FIXME: Could this be removed?
|
|
||||||
consumes: postgresql
|
consumes: postgresql
|
||||||
|
|
||||||
%pre-start
|
%directory ${SERVICE_ROOT}/custom/conf
|
||||||
name: working directory
|
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/
|
|
||||||
|
|
||||||
%pre-start
|
%configuration gitea.cfg ${SERVICE_ROOT}/custom/conf/app.ini
|
||||||
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}
|
|
||||||
|
|
||||||
%pre-start
|
%pre-start
|
||||||
name: gitea database creation
|
name: gitea database creation
|
||||||
|
|
|
@ -236,7 +236,7 @@ class Service
|
||||||
end
|
end
|
||||||
|
|
||||||
Process.exec command, args,
|
Process.exec command, args,
|
||||||
chdir: @reference.directory.try { |x| evaluate x },
|
chdir: (@reference.directory.try { |x| evaluate x } || root),
|
||||||
env: build_environment
|
env: build_environment
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,41 @@ class ServiceDefinition
|
||||||
@consumes = specs["consumes"]?.try &.as_a_or_s.map { |x| Consumes.new x } || Array(Consumes).new
|
@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
|
@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
|
end
|
||||||
|
|
||||||
def self.load(path)
|
def self.load(path)
|
||||||
|
|
Loading…
Reference in New Issue