Service#root, Environment#root.
parent
1f9264f97b
commit
27c9a525f6
|
@ -6,6 +6,7 @@ variables+=(
|
||||||
LIBEXECDIR '$(PREFIX)/libexec'
|
LIBEXECDIR '$(PREFIX)/libexec'
|
||||||
SYSCONFDIR '/etc'
|
SYSCONFDIR '/etc'
|
||||||
VARSTATEDIR '/var'
|
VARSTATEDIR '/var'
|
||||||
|
DATADIR '/srv'
|
||||||
)
|
)
|
||||||
|
|
||||||
targets=(service status get-port gen-config)
|
targets=(service status get-port gen-config)
|
||||||
|
|
|
@ -1,28 +1,28 @@
|
||||||
command: ./gitea -C . -w . -c ./custom/conf/app.ini
|
command: ./gitea -C . -w . -c ./custom/conf/app.ini
|
||||||
# deamon's working directory
|
# deamon's working directory
|
||||||
directory: /srv/${ENVIRONMENT}/gitea
|
directory: ${SERVICE_ROOT} # FIXME: Could this be removed?
|
||||||
consumes: postgresql
|
consumes: postgresql
|
||||||
|
|
||||||
%check
|
%check
|
||||||
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: /srv/${ENVIRONMENT}/gitea/custom/conf/
|
directory: ${SERVICE_ROOT}/custom/conf/
|
||||||
command: mkdir -p /srv/${ENVIRONMENT}/gitea/custom/conf/
|
command: mkdir -p ${SERVICE_ROOT}/custom/conf/
|
||||||
|
|
||||||
%check
|
%check
|
||||||
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: /srv/${ENVIRONMENT}/gitea/gitea
|
file: ${SERVICE_ROOT}/gitea
|
||||||
command: ln -s $(which gitea) /srv/${ENVIRONMENT}/gitea/
|
command: ln -s $(which gitea) ${SERVICE_ROOT}/gitea
|
||||||
|
|
||||||
%check
|
%check
|
||||||
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: /srv/${ENVIRONMENT}/gitea/custom/conf/app.ini
|
file: ${SERVICE_ROOT}/custom/conf/app.ini
|
||||||
command: gen-config gitea.cfg /srv/${ENVIRONMENT}/gitea/custom/conf/app.ini postgresql=${POSTGRESQL_PROVIDER}
|
command: gen-config gitea.cfg ${SERVICE_ROOT}/custom/conf/app.ini postgresql=${POSTGRESQL_PROVIDER}
|
||||||
|
|
||||||
%check
|
%check
|
||||||
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: /srv/${ENVIRONMENT}/gitea/db_is_setup
|
file: ${SERVICE_ROOT}/db_is_setup
|
||||||
command: pg_create_user.sh --pghost=localhost --pgport=$(get-port $POSTGRESQL_PROVIDER) --pgdatadir=/srv/$POSTGRESQL_ENVIRONMENT/postgresql --pguser=postgres --dbuser=${ENVIRONMENT}_gitea --dbpassfile=/srv/$ENVIRONMENT/gitea/password_main --dbname=${ENVIRONMENT}_gitea_db create_user_and_db && touch /srv/$ENVIRONMENT/gitea/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
|
||||||
|
|
|
@ -1,27 +1,27 @@
|
||||||
name: postgresql
|
name: postgresql
|
||||||
user: postgres
|
user: postgres
|
||||||
command: postgres -D /srv/${ENVIRONMENT}/postgresql -k /tmp/postgresql-${ENVIRONMENT}
|
command: postgres -D ${SERVICE_ROOT} -k /tmp/postgresql-${ENVIRONMENT}
|
||||||
#stop-command: kill -HUP ${PID}
|
#stop-command: kill -HUP ${PID}
|
||||||
environment-variables:
|
environment-variables:
|
||||||
- PGROOT=/srv/${ENVIRONMENT}/postgresql
|
- PGROOT=${SERVICE_ROOT}
|
||||||
provides: postgresql
|
provides: postgresql
|
||||||
|
|
||||||
%check
|
%check
|
||||||
name: database directory creation
|
name: database directory creation
|
||||||
directory: /srv/${ENVIRONMENT}/postgresql
|
directory: ${SERVICE_ROOT}
|
||||||
command: mkdir -p /srv/${ENVIRONMENT}/postgresql && chown postgres:postgres /srv/${ENVIRONMENT}/postgresql
|
command: mkdir -p ${SERVICE_ROOT} && chown postgres:postgres ${SERVICE_ROOT}
|
||||||
|
|
||||||
%check
|
%check
|
||||||
name: database creation
|
name: database creation
|
||||||
file: /srv/${ENVIRONMENT}/postgresql/base
|
file: ${SERVICE_ROOT}/base
|
||||||
command: su - postgres -c "initdb --locale en_US.UTF-8 -D '/srv/${ENVIRONMENT}/postgresql'" && rm /srv/${ENVIRONMENT}/postgresql/postgresql.conf
|
command: su - postgres -c "initdb --locale en_US.UTF-8 -D '${SERVICE_ROOT}'" && rm ${SERVICE_ROOT}/postgresql.conf
|
||||||
|
|
||||||
%check
|
%check
|
||||||
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: /srv/${ENVIRONMENT}/postgresql/postgresql.conf
|
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 /srv/${ENVIRONMENT}/postgresql/postgresql.conf && chown postgres:postgres /srv/${ENVIRONMENT}/postgresql/postgresql.conf
|
command: gen-config postgresql.conf ${SERVICE_ROOT}/postgresql.conf && chown postgres:postgres ${SERVICE_ROOT}/postgresql.conf
|
||||||
|
|
||||||
%check
|
%check
|
||||||
name: sockets directory
|
name: sockets directory
|
||||||
|
|
|
@ -9,4 +9,5 @@ SYSTEM_CONFIGURATION_DIRECTORY = "@SYSCONFDIR@"
|
||||||
SHARED_DATA_DIRECTORY = "@SHAREDIR@"
|
SHARED_DATA_DIRECTORY = "@SHAREDIR@"
|
||||||
OWN_LIBEXEC_DIR = "@LIBEXECDIR@/service"
|
OWN_LIBEXEC_DIR = "@LIBEXECDIR@/service"
|
||||||
CACHE_DIRECTORY = "@VARSTATEDIR@/cache"
|
CACHE_DIRECTORY = "@VARSTATEDIR@/cache"
|
||||||
|
SERVED_DATA_DIRECTORY = "@DATADIR@"
|
||||||
|
|
||||||
|
|
|
@ -81,8 +81,10 @@ class GenConfig::Context
|
||||||
|
|
||||||
options["id"] = service.full_id
|
options["id"] = service.full_id
|
||||||
options["name"] = service.name
|
options["name"] = service.name
|
||||||
|
options["service_root"] = service.root
|
||||||
|
|
||||||
options["environment"] = environment.name
|
options["environment"] = environment.name
|
||||||
|
options["environment_root"] = environment.root
|
||||||
|
|
||||||
providers = Hash(String, Variables).new
|
providers = Hash(String, Variables).new
|
||||||
service.providers.each do |token, provider|
|
service.providers.each do |token, provider|
|
||||||
|
@ -105,14 +107,15 @@ class GenConfig::Context
|
||||||
`get-port #{service}`.chomp
|
`get-port #{service}`.chomp
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# FIXME: Move this to a separate binary?
|
||||||
options["random_password"] = Crinja.function do
|
options["random_password"] = Crinja.function do
|
||||||
id = (arguments.varargs[0]? || options["id"]).to_s
|
id = (arguments.varargs[0]? || options["id"]).to_s
|
||||||
password_id = arguments.varargs[1]? || "main"
|
password_id = arguments.varargs[1]? || "main"
|
||||||
|
|
||||||
env, service = Service.parse_id id
|
_service = Service.get_by_id(id).not_nil!
|
||||||
|
|
||||||
# FIXME: hardcoded path
|
# FIXME: hardcoded path
|
||||||
password_file = "/srv/#{env}/#{service}/password_#{password_id}"
|
password_file = "#{_service.root}/password_#{password_id}"
|
||||||
|
|
||||||
if File.exists? password_file
|
if File.exists? password_file
|
||||||
File.read password_file
|
File.read password_file
|
||||||
|
|
|
@ -11,6 +11,9 @@ class Environment
|
||||||
getter domain_name : String?
|
getter domain_name : String?
|
||||||
getter checks = Array(ServiceDefinition::Checks).new
|
getter checks = Array(ServiceDefinition::Checks).new
|
||||||
|
|
||||||
|
# The place we’ll put services’ data and configuration.
|
||||||
|
@root : String?
|
||||||
|
|
||||||
def initialize()
|
def initialize()
|
||||||
initialize "root"
|
initialize "root"
|
||||||
end
|
end
|
||||||
|
@ -38,6 +41,10 @@ class Environment
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def root
|
||||||
|
@root || "#{SERVED_DATA_DIRECTORY}/#{@name}"
|
||||||
|
end
|
||||||
|
|
||||||
class_getter root = Environment.new
|
class_getter root = Environment.new
|
||||||
class_getter all = [@@root] of Environment
|
class_getter all = [@@root] of Environment
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,11 @@ class Service
|
||||||
getter environment : Environment
|
getter environment : Environment
|
||||||
getter providers = ProvidersList.new
|
getter providers = ProvidersList.new
|
||||||
|
|
||||||
|
getter domain : String?
|
||||||
|
|
||||||
|
# The place we’ll store configuration and data.
|
||||||
|
@root : String?
|
||||||
|
|
||||||
class Exception < ::Exception
|
class Exception < ::Exception
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -56,6 +61,8 @@ class Service
|
||||||
Environment.get env
|
Environment.get env
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@root = assignments["root"]?.try &.as_s
|
||||||
|
|
||||||
specs.sections.select(&.name.==("consumes")).each do |section|
|
specs.sections.select(&.name.==("consumes")).each do |section|
|
||||||
env, provider = Service.parse_id section.content["from"].as_s
|
env, provider = Service.parse_id section.content["from"].as_s
|
||||||
@providers[section.options[0]] = "#{env}/#{provider}"
|
@providers[section.options[0]] = "#{env}/#{provider}"
|
||||||
|
@ -66,9 +73,12 @@ class Service
|
||||||
file = [
|
file = [
|
||||||
"name: #{@reference.name}",
|
"name: #{@reference.name}",
|
||||||
"environment: #{@environment.name}"
|
"environment: #{@environment.name}"
|
||||||
# FIXME: consumed tokens are missing.
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
if @root
|
||||||
|
file << "root: #{@root}"
|
||||||
|
end
|
||||||
|
|
||||||
@providers.each do |token, provider|
|
@providers.each do |token, provider|
|
||||||
file << "%consumes #{token}"
|
file << "%consumes #{token}"
|
||||||
file << " from: #{provider}"
|
file << " from: #{provider}"
|
||||||
|
@ -109,6 +119,10 @@ class Service
|
||||||
@reference.consumes
|
@reference.consumes
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def root
|
||||||
|
@root || "#{@environment.root}/#{name}"
|
||||||
|
end
|
||||||
|
|
||||||
def provides?(token)
|
def provides?(token)
|
||||||
provides.any? do |provider|
|
provides.any? do |provider|
|
||||||
provider.token == token
|
provider.token == token
|
||||||
|
@ -118,13 +132,20 @@ class Service
|
||||||
private def build_environment
|
private def build_environment
|
||||||
env = {} of String => String
|
env = {} of String => String
|
||||||
|
|
||||||
|
env["SERVICE_ROOT"] = root
|
||||||
env["SERVICE_ID"] = full_id
|
env["SERVICE_ID"] = full_id
|
||||||
env["ENVIRONMENT"] = @environment.name
|
env["ENVIRONMENT"] = @environment.name
|
||||||
env["ENVIRONMENT_TYPE"] = @environment.type.to_s
|
env["ENVIRONMENT_TYPE"] = @environment.type.to_s
|
||||||
|
|
||||||
@providers.each do |token, provider|
|
@providers.each do |token, provider|
|
||||||
|
service_provider = Service.get_by_id provider
|
||||||
|
|
||||||
|
# FIXME: Warning?
|
||||||
|
next if service_provider.nil?
|
||||||
|
|
||||||
env["#{token.upcase}_PROVIDER"] = provider
|
env["#{token.upcase}_PROVIDER"] = provider
|
||||||
env["#{token.upcase}_ENVIRONMENT"] = provider.gsub /\/.*/, ""
|
env["#{token.upcase}_ENVIRONMENT"] = service_provider.environment.name
|
||||||
|
env["#{token.upcase}_ROOT"] = service_provider.root
|
||||||
end
|
end
|
||||||
|
|
||||||
env["SERVICE_TOKENS"] = @providers.to_a.map(&.[0]).join ':'
|
env["SERVICE_TOKENS"] = @providers.to_a.map(&.[0]).join ':'
|
||||||
|
@ -145,11 +166,13 @@ class Service
|
||||||
|
|
||||||
# FIXME: Is working on ${} really a good idea?
|
# FIXME: Is working on ${} really a good idea?
|
||||||
private def evaluate(string)
|
private def evaluate(string)
|
||||||
string.gsub /\${[a-zA-Z]+}/ do |match|
|
string.gsub /\${[a-zA-Z_]+}/ do |match|
|
||||||
match = match[2..match.size-2]
|
match = match[2..match.size-2]
|
||||||
|
|
||||||
if match.downcase == "environment"
|
if match.downcase == "environment"
|
||||||
@environment.name
|
@environment.name
|
||||||
|
elsif match.downcase == "service_root"
|
||||||
|
root
|
||||||
else
|
else
|
||||||
""
|
""
|
||||||
end
|
end
|
||||||
|
@ -162,12 +185,12 @@ class Service
|
||||||
|
|
||||||
check.file.try do |file|
|
check.file.try do |file|
|
||||||
file = evaluate file
|
file = evaluate file
|
||||||
run_check = true if ! File.exists? evaluate file
|
run_check = true if ! File.exists? file
|
||||||
end
|
end
|
||||||
|
|
||||||
check.directory.try do |directory|
|
check.directory.try do |directory|
|
||||||
directory = evaluate directory
|
directory = evaluate directory
|
||||||
run_check = true if ! Dir.exists? evaluate directory
|
run_check = true if ! Dir.exists? directory
|
||||||
end
|
end
|
||||||
|
|
||||||
unless run_check
|
unless run_check
|
||||||
|
|
Loading…
Reference in New Issue