%check entries are now called %pre-start hooks.
parent
34a2982ef4
commit
7b02cffb9e
|
@ -3,26 +3,26 @@ command: ./gitea -C . -w . -c ./custom/conf/app.ini
|
||||||
directory: ${SERVICE_ROOT} # FIXME: Could this be removed?
|
directory: ${SERVICE_ROOT} # FIXME: Could this be removed?
|
||||||
consumes: postgresql
|
consumes: postgresql
|
||||||
|
|
||||||
%check
|
%pre-start
|
||||||
name: working directory
|
name: working directory
|
||||||
# 'command' is run only if this directory doesn't exist
|
# 'command' is run only if this directory doesn't exist
|
||||||
directory: ${SERVICE_ROOT}/custom/conf/
|
unless-directory: ${SERVICE_ROOT}/custom/conf/
|
||||||
command: mkdir -p ${SERVICE_ROOT}/custom/conf/
|
command: mkdir -p ${SERVICE_ROOT}/custom/conf/
|
||||||
|
|
||||||
%check
|
%pre-start
|
||||||
name: symlink
|
name: symlink
|
||||||
# 'command' is run only if this directory doesn't exist
|
# 'command' is run only if this directory doesn't exist
|
||||||
file: ${SERVICE_ROOT}/gitea
|
unless-file: ${SERVICE_ROOT}/gitea
|
||||||
command: ln -s $(which gitea) ${SERVICE_ROOT}/gitea
|
command: ln -s $(which gitea) ${SERVICE_ROOT}/gitea
|
||||||
|
|
||||||
%check
|
%pre-start
|
||||||
name: configuration file
|
name: configuration file
|
||||||
# 'command' is run only if this file doesn't exist
|
# 'command' is run only if this file doesn't exist
|
||||||
file: ${SERVICE_ROOT}/custom/conf/app.ini
|
unless-file: ${SERVICE_ROOT}/custom/conf/app.ini
|
||||||
command: gen-config gitea.cfg ${SERVICE_ROOT}/custom/conf/app.ini postgresql=${POSTGRESQL_PROVIDER}
|
command: gen-config gitea.cfg ${SERVICE_ROOT}/custom/conf/app.ini postgresql=${POSTGRESQL_PROVIDER}
|
||||||
|
|
||||||
%check
|
%pre-start
|
||||||
name: gitea database creation
|
name: gitea database creation
|
||||||
# 'command' is run only if this directory doesn't exist
|
# 'command' is run only if this directory doesn't exist
|
||||||
file: ${SERVICE_ROOT}/db_is_setup
|
unless-file: ${SERVICE_ROOT}/db_is_setup
|
||||||
command: pg_create_user.sh --pghost=localhost --pgport=$(get-port $POSTGRESQL_PROVIDER) --pgdatadir=$POSTGRESQL_ROOT --pguser=postgres --dbuser=${ENVIRONMENT}_gitea --dbpassfile=${SERVICE_ROOT}/password_main --dbname=${ENVIRONMENT}_gitea_db create_user_and_db && touch ${SERVICE_ROOT}/db_is_setup
|
command: pg_create_user.sh --pghost=localhost --pgport=$(get-port $POSTGRESQL_PROVIDER) --pgdatadir=$POSTGRESQL_ROOT --pguser=postgres --dbuser=${ENVIRONMENT}_gitea --dbpassfile=${SERVICE_ROOT}/password_main --dbname=${ENVIRONMENT}_gitea_db create_user_and_db && touch ${SERVICE_ROOT}/db_is_setup
|
||||||
|
|
|
@ -6,26 +6,26 @@ environment-variables:
|
||||||
- PGROOT=${SERVICE_ROOT}
|
- PGROOT=${SERVICE_ROOT}
|
||||||
provides: postgresql
|
provides: postgresql
|
||||||
|
|
||||||
%check
|
%pre-start
|
||||||
name: database directory creation
|
name: database directory creation
|
||||||
directory: ${SERVICE_ROOT}
|
unless-directory: ${SERVICE_ROOT}
|
||||||
command: mkdir -p ${SERVICE_ROOT} && chown postgres:postgres ${SERVICE_ROOT}
|
command: mkdir -p ${SERVICE_ROOT} && chown postgres:postgres ${SERVICE_ROOT}
|
||||||
|
|
||||||
%check
|
%pre-start
|
||||||
name: database creation
|
name: database creation
|
||||||
file: ${SERVICE_ROOT}/base
|
unless-file: ${SERVICE_ROOT}/base
|
||||||
command: su - postgres -c "initdb --locale en_US.UTF-8 -D '${SERVICE_ROOT}'" && rm ${SERVICE_ROOT}/postgresql.conf
|
command: su - postgres -c "initdb --locale en_US.UTF-8 -D '${SERVICE_ROOT}'" && rm ${SERVICE_ROOT}/postgresql.conf
|
||||||
|
|
||||||
%check
|
%pre-start
|
||||||
name: database configuration
|
name: database configuration
|
||||||
# once this file is created, there is no need to perform the command
|
# once this file is created, there is no need to perform the command
|
||||||
file: ${SERVICE_ROOT}/postgresql.conf
|
unless-file: ${SERVICE_ROOT}/postgresql.conf
|
||||||
# gen-config inherits its parameters from the environment
|
# gen-config inherits its parameters from the environment
|
||||||
command: gen-config postgresql.conf ${SERVICE_ROOT}/postgresql.conf && chown postgres:postgres ${SERVICE_ROOT}/postgresql.conf
|
command: gen-config postgresql.conf ${SERVICE_ROOT}/postgresql.conf && chown postgres:postgres ${SERVICE_ROOT}/postgresql.conf
|
||||||
|
|
||||||
%check
|
%pre-start
|
||||||
name: sockets directory
|
name: sockets directory
|
||||||
directory: /tmp/postgresql-${ENVIRONMENT}
|
unless-directory: /tmp/postgresql-${ENVIRONMENT}
|
||||||
# FIXME: impose permissions
|
# FIXME: impose permissions
|
||||||
command: mkdir -p /tmp/postgresql-${ENVIRONMENT} && chown postgres:postgres /tmp/postgresql-${ENVIRONMENT}
|
command: mkdir -p /tmp/postgresql-${ENVIRONMENT} && chown postgres:postgres /tmp/postgresql-${ENVIRONMENT}
|
||||||
# FIXME: add postgresql-check-db-dir around here
|
# FIXME: add postgresql-pre-start-db-dir around here
|
||||||
|
|
|
@ -9,7 +9,7 @@ class Environment
|
||||||
getter name : String
|
getter name : String
|
||||||
getter type : Type = Type::Prefix
|
getter type : Type = Type::Prefix
|
||||||
getter domain_name : String?
|
getter domain_name : String?
|
||||||
getter checks = Array(ServiceDefinition::Checks).new
|
getter pre_start_hooks = Array(ServiceDefinition::Hook).new
|
||||||
|
|
||||||
# The place we’ll put services’ data and configuration.
|
# The place we’ll put services’ data and configuration.
|
||||||
@root : String?
|
@root : String?
|
||||||
|
@ -21,12 +21,12 @@ class Environment
|
||||||
def initialize(@name, type = "prefix")
|
def initialize(@name, type = "prefix")
|
||||||
@type = Type.parse type
|
@type = Type.parse type
|
||||||
|
|
||||||
@checks = Array(ServiceDefinition::Checks).new
|
@pre_start_hooks = Array(ServiceDefinition::Hook).new
|
||||||
|
|
||||||
# FIXME: Should this *really* be here?
|
# FIXME: Should this *really* be here?
|
||||||
@checks << ServiceDefinition::Checks.new "Creating data directory",
|
@pre_start_hooks << ServiceDefinition::Hook.new "Creating data directory",
|
||||||
"mkdir -p /srv/${ENVIRONMENT} && chmod a+rwt /srv/${ENVIRONMENT}",
|
"mkdir -p /srv/${ENVIRONMENT} && chmod a+rwt /srv/${ENVIRONMENT}",
|
||||||
directory: "/srv/${ENVIRONMENT}"
|
unless_directory: "/srv/${ENVIRONMENT}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def initialize(@name, specs : SpecParser)
|
def initialize(@name, specs : SpecParser)
|
||||||
|
@ -37,7 +37,7 @@ class Environment
|
||||||
end
|
end
|
||||||
|
|
||||||
specs.sections.select(&.name.==("check")).each do |check|
|
specs.sections.select(&.name.==("check")).each do |check|
|
||||||
@checks << ServiceDefinition::Checks.new check
|
@pre_start_hooks << ServiceDefinition::Hook.new check
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -179,28 +179,32 @@ class Service
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def pre_start_hooks
|
||||||
|
@environment.pre_start_hooks + @reference.pre_start_hooks
|
||||||
|
end
|
||||||
|
|
||||||
def start(pid_dir : String, log_dir : String)
|
def start(pid_dir : String, log_dir : String)
|
||||||
(@environment.checks + @reference.checks).each do |check|
|
pre_start_hooks.each do |hook|
|
||||||
run_check = false
|
run_hook = false
|
||||||
|
|
||||||
check.file.try do |file|
|
hook.unless_file.try do |file|
|
||||||
file = evaluate file
|
file = evaluate file
|
||||||
run_check = true if ! File.exists? file
|
run_hook = true if ! File.exists? file
|
||||||
end
|
end
|
||||||
|
|
||||||
check.directory.try do |directory|
|
hook.unless_directory.try do |directory|
|
||||||
directory = evaluate directory
|
directory = evaluate directory
|
||||||
run_check = true if ! Dir.exists? directory
|
run_hook = true if ! Dir.exists? directory
|
||||||
end
|
end
|
||||||
|
|
||||||
unless run_check
|
unless run_hook
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
puts " - #{check.name}"
|
puts " - #{hook.name}"
|
||||||
|
|
||||||
child = Process.fork do
|
child = Process.fork do
|
||||||
Process.exec "sh", ["-c", check.command],
|
Process.exec "sh", ["-c", hook.command],
|
||||||
output: Process::Redirect::Inherit,
|
output: Process::Redirect::Inherit,
|
||||||
error: Process::Redirect::Inherit,
|
error: Process::Redirect::Inherit,
|
||||||
env: build_environment
|
env: build_environment
|
||||||
|
|
|
@ -18,19 +18,21 @@ class ServiceDefinition
|
||||||
def initialize(@token)
|
def initialize(@token)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
struct Checks
|
struct Hook
|
||||||
getter name : String
|
getter name : String
|
||||||
getter command : String
|
getter command : String
|
||||||
getter directory : String?
|
getter unless_directory : String?
|
||||||
getter file : String?
|
getter unless_file : String?
|
||||||
|
|
||||||
def initialize(@name, @command, @file = nil, @directory = nil)
|
def initialize(@name, @command, @unless_file = nil, @unless_directory = nil)
|
||||||
end
|
end
|
||||||
def initialize(section : SpecParser::Section)
|
def initialize(section : SpecParser::Section)
|
||||||
@name = section.content["name"].as_s
|
@name = section.content["name"].as_s
|
||||||
@file = section.content["file"]?.try &.as_s
|
|
||||||
@directory = section.content["directory"]?.try &.as_s
|
|
||||||
@command = section.content["command"].as_s
|
@command = section.content["command"].as_s
|
||||||
|
|
||||||
|
@unless_directory = section.content["unless-directory"]?
|
||||||
|
.try &.as_s
|
||||||
|
@unless_file = section.content["unless-file"]?.try &.as_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -44,7 +46,7 @@ class ServiceDefinition
|
||||||
getter provides : String?
|
getter provides : String?
|
||||||
getter consumes : Array(Consumes)
|
getter consumes : Array(Consumes)
|
||||||
getter environment_variables : Array(String)
|
getter environment_variables : Array(String)
|
||||||
getter checks : Array(Checks)
|
getter pre_start_hooks : Array(Hook)
|
||||||
getter provides : Array(Provides)
|
getter provides : Array(Provides)
|
||||||
|
|
||||||
def initialize(@name, specs : SpecParser)
|
def initialize(@name, specs : SpecParser)
|
||||||
|
@ -56,8 +58,9 @@ class ServiceDefinition
|
||||||
@user = specs["user"]?.try &.as_s
|
@user = specs["user"]?.try &.as_s
|
||||||
@provides = specs["provides"]?.try &.as_a_or_s.map { |x| Provides.new x } || Array(Provides).new
|
@provides = specs["provides"]?.try &.as_a_or_s.map { |x| Provides.new x } || Array(Provides).new
|
||||||
@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
|
||||||
@checks = sections.select(&.name.== "check").map { |x| Checks.new x } || Array(Checks).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
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.load(path)
|
def self.load(path)
|
||||||
|
|
Loading…
Reference in New Issue