Rework SAMBRO

This commit is contained in:
Disassembler 2019-10-05 16:10:29 +02:00
parent 985dd2998a
commit 9b18c94ddd
Signed by: Disassembler
GPG Key ID: 524BD33A0EE29499
11 changed files with 67 additions and 69 deletions

View File

@ -2,8 +2,8 @@
"version": "0.0.1-190620", "version": "0.0.1-190620",
"meta": { "meta": {
"title": "Sahana Eden - Demo", "title": "Sahana Eden - Demo",
"desc-cs": "Řízení humanítární činnosti", "desc-cs": "Řízení humanítární činnosti - Demo instance",
"desc-en": "Management of humanitarian activities", "desc-en": "Management of humanitarian activities - Demo instance",
"license": "GPL", "license": "GPL",
}, },
"containers": { "containers": {
@ -13,8 +13,10 @@
"sahana-demo-postgres" "sahana-demo-postgres"
], ],
"mounts": [ "mounts": [
["DIR", "/srv/sahana-demo/sahana_conf", "/srv/sahana/conf"], ["DIR", "/srv/sahana-demo/sahana_conf", "/srv/web2py/applications/eden/models"],
["DIR", "/srv/sahana-demo/sahana_data", "/srv/sahana/data"] ["DIR", "/srv/sahana-demo/sahana_data/default", "/srv/web2py/applications/eden/modules/templates/default"],
["DIR", "/srv/sahana-demo/sahana_data/databases", "/srv/web2py/applications/eden/databases"],
["DIR", "/srv/sahana-demo/sahana_data/uploads", "/srv/web2py/applications/eden/uploads"]
] ]
}, },
"sahana-demo-postgres": { "sahana-demo-postgres": {

View File

@ -13,8 +13,10 @@
"sahana-postgres" "sahana-postgres"
], ],
"mounts": [ "mounts": [
["DIR", "/srv/sahana/sahana_conf", "/srv/sahana/conf"], ["DIR", "/srv/sahana/sahana_conf", "/srv/web2py/applications/eden/models"],
["DIR", "/srv/sahana/sahana_data", "/srv/sahana/data"] ["DIR", "/srv/sahana/sahana_data/Spotter", "/srv/web2py/applications/eden/modules/templates/Spotter"],
["DIR", "/srv/sahana/sahana_data/databases", "/srv/web2py/applications/eden/databases"],
["DIR", "/srv/sahana/sahana_data/uploads", "/srv/web2py/applications/eden/uploads"]
] ]
}, },
"sahana-postgres": { "sahana-postgres": {

View File

@ -3,29 +3,39 @@ set -ev
cd $(realpath $(dirname "${0}"))/install cd $(realpath $(dirname "${0}"))/install
# Check prerequisites # Create Postgres instance
[ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1 mkdir -p /srv/sambro/postgres_data
chown -R 105432:105432 /srv/sambro/postgres_data
chmod 700 /srv/sambro/postgres_data
lxc-execute -n sambro-postgres -- initdb -D /var/lib/postgresql
# Configure Postgres
cp postgres_data/postgresql.conf /srv/sambro/postgres_data/postgresql.conf
cp postgres_data/pg_hba.conf /srv/sambro/postgres_data/pg_hba.conf
# Create PostgreSQL user and database # Create PostgreSQL user and database
export SAMBRO_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=') export SAMBRO_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 postgres -- psql service sambro-postgres start
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 sambro-postgres -- psql
# Prepare persistent directory structure # Prepare persistent directory structure
mkdir -p /srv/sambro/conf /srv/sambro/data/databases /srv/sambro/data/uploads /srv/sambro/data/SAMBRO mkdir -p /srv/sambro/sahana_conf /srv/sambro/sahana_data/databases /srv/sambro/sahana_data/uploads /srv/sambro/sahana_data/SAMBRO
chown -R 8001:8001 /srv/sambro/conf /srv/sambro/data chown -R 108001:108001 /srv/sambro/sahana_conf /srv/sambro/sahana_data
cp -rp /var/lib/lxc/shared/sahana/srv/web2py/applications/eden/models/. /srv/sambro/conf lxc-execute sambro -- tar -cC /srv/web2py/applications/eden/models . | tar -xC /srv/sambro/sahana_conf
cp -rp /var/lib/lxc/shared/sahana/srv/web2py/applications/eden/modules/templates/SAMBRO/. /srv/sambro/data/SAMBRO lxc-execute sambro -- tar -cC /srv/web2py/applications/eden/modules/templates/SAMBRO . | tar -xC /srv/sambro/sahana_data/SAMBRO
# Configure SAMBRO # Configure SAMBRO
export SAMBRO_HMAC=$(head -c 18 /dev/urandom | base64 | tr -d '+/=') export SAMBRO_HMAC=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
export SAMBRO_ADMIN_USER=admin@example.com export SAMBRO_ADMIN_USER=admin@example.com
export SAMBRO_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=') export SAMBRO_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
envsubst <srv/sambro/conf/000_config.py >/srv/sambro/conf/000_config.py envsubst <sahana_conf/000_config.py >/srv/sambro/sahana_conf/000_config.py
mkdir -p /var/lib/lxc/sambro/sambro/srv/web2py/applications/eden/modules/templates/default/users # TODO:
envsubst <masterUsers.csv >/var/lib/lxc/sambro/sambro/srv/web2py/applications/eden/modules/templates/default/users/masterUsers.csv #mkdir -p /var/lib/lxc/sambro/sambro/srv/web2py/applications/eden/modules/templates/default/users
chown -R 8001:8001 /var/lib/lxc/sambro/sambro/srv/web2py #envsubst <masterUsers.csv >/var/lib/lxc/sambro/sambro/srv/web2py/applications/eden/modules/templates/default/users/masterUsers.csv
cp srv/sambro/conf/00_settings.py /srv/sambro/conf/00_settings.py #chown -R 8001:8001 /var/lib/lxc/sambro/sambro/srv/web2py
cp srv/sambro/data/SAMBRO/config.py /srv/sambro/data/SAMBRO/config.py cp sahana_conf/00_settings.py /srv/sambro/sahana_conf/00_settings.py
cp sahana_data/SAMBRO/config.py /srv/sambro/sahana_data/SAMBRO/config.py
chown -R 108001:108001 /srv/sambro/sahana_conf /srv/sambro/sahana_data
# Populate database # Populate database
lxc-execute -u 8001 -g 8001 sambro -- sh -c 'cd /srv/web2py; ./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py' lxc-execute -u 8001 -g 8001 sambro -- sh -c 'cd /srv/web2py; ./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py'
@ -37,15 +47,11 @@ if [ ${DEBUG:-0} -eq 0 ]; then
sed -i 's/#settings.base.prepopulate = 0/settings.base.prepopulate = 0/' /srv/sambro/conf/000_config.py sed -i 's/#settings.base.prepopulate = 0/settings.base.prepopulate = 0/' /srv/sambro/conf/000_config.py
fi fi
# Install service
cp etc/init.d/sambro /etc/init.d/sambro
rc-update -u
# Install config update script # Install config update script
cp srv/sambro/update-conf.sh /srv/sambro/update-conf.sh cp update-conf.sh /srv/sambro/update-conf.sh
# Stop services required for build # Stop services required for setup
[ ! -z ${STOP_POSTGRES} ] && service postgres stop service sambro-postgres stop
# Register application # Register application
vmmgr register-app sambro sambro "${SAMBRO_ADMIN_USER}" "${SAMBRO_ADMIN_PWD}" vmmgr register-app sambro sambro "${SAMBRO_ADMIN_USER}" "${SAMBRO_ADMIN_PWD}"

View File

@ -1,23 +0,0 @@
#!/sbin/openrc-run
description="SAMBRO container"
depend() {
need postgres
}
start() {
lxc-start sambro
}
start_post() {
vmmgr register-proxy sambro
}
stop_pre() {
vmmgr unregister-proxy sambro
}
stop() {
lxc-stop sambro
}

View File

@ -1,12 +0,0 @@
IMAGE sambro_0.0.1-190620
LAYER alpine3.9_3.9.4-190620
LAYER alpine3.9-python2.7_2.7.16-190620
LAYER sahana-shared_0.0.1-190620
MOUNT DIR /srv/sambro/conf srv/web2py/applications/eden/models
MOUNT DIR /srv/sambro/data/SAMBRO srv/web2py/applications/eden/modules/templates/SAMBRO
MOUNT DIR /srv/sambro/data/databases srv/web2py/applications/eden/databases
MOUNT DIR /srv/sambro/data/uploads srv/web2py/applications/eden/uploads
CMD s6-svscan /etc/services.d

29
lxc-apps/sambro/meta Normal file
View File

@ -0,0 +1,29 @@
{
"version": "0.0.1-190620",
"meta": {
"title": "Sahana Eden - SAMBRO",
"desc-cs": "Řízení humanítární činnosti - Centrum hlášení a výstrah",
"desc-en": "Management of humanitarian activities - Reporting and alerting center",
"license": "GPL",
},
"containers": {
"sambro": {
"image": "sahana_0.0.1-190620",
"depends": [
"sambro-postgres"
],
"mounts": [
["DIR", "/srv/sambro/sahana_conf", "/srv/web2py/applications/eden/models"],
["DIR", "/srv/sambro/sahana_data/SAMBRO", "/srv/web2py/applications/eden/modules/templates/SAMBRO"],
["DIR", "/srv/sambro/sahana_data/databases", "/srv/web2py/applications/eden/databases"],
["DIR", "/srv/sambro/sahana_data/uploads", "/srv/web2py/applications/eden/uploads"]
]
},
"sambro-postgres": {
"image": "postgis_11.3.0-190620",
"mounts": [
["DIR", "/srv/sambro/postgres_data", "/var/lib/postgresql"]
]
}
}
}

View File

@ -1,14 +1,8 @@
#!/bin/sh #!/bin/sh
set -ev set -ev
# Remove service # Remove persistent data
rm -f /etc/init.d/sambro rm -rf /srv/sambro
rc-update -u
# Drop database and user
[ ! -e /run/openrc/started/postgres ] && service postgres start && STOP_POSTGRES=1
echo 'DROP DATABASE IF EXISTS sambro; DROP ROLE IF EXISTS sambro;' | lxc-attach -u 5432 -g 5432 postgres -- psql
[ ! -z ${STOP_POSTGRES} ] && service postgres stop
# Unregister application # Unregister application
vmmgr unregister-app sambro vmmgr unregister-app sambro