2018-01-27 22:26:37 +01:00
|
|
|
#!/bin/sh
|
2018-10-28 16:04:11 +01:00
|
|
|
set -ev
|
2017-06-25 20:49:41 +02:00
|
|
|
|
2020-02-09 15:56:37 +01:00
|
|
|
# Create containers
|
|
|
|
spoc-container create \
|
|
|
|
-m sahana/postgres_data:var/lib/postgresql \
|
|
|
|
sahana-postgres postgis_3.0.0-200207
|
|
|
|
spoc-container create \
|
|
|
|
-d sahana-postgres \
|
|
|
|
-m sahana/sahana_conf:srv/web2py/applications/eden/models \
|
|
|
|
-m sahana/sahana_data/Spotter:srv/web2py/applications/eden/modules/templates/Spotter \
|
|
|
|
-m sahana/sahana_data/databases:srv/web2py/applications/eden/databases \
|
|
|
|
-m sahana/sahana_data/uploads:srv/web2py/applications/eden/uploads \
|
|
|
|
sahana sahana_0.0.1-200207
|
|
|
|
|
|
|
|
# TODO: Populate from spoc
|
|
|
|
LAYER_DIR="/var/lib/spoc/layers"
|
|
|
|
VOLUME_DIR="/var/lib/spoc/volumes/sahana"
|
|
|
|
POSTGRES_UID=70
|
|
|
|
POSTGRES_GID=70
|
|
|
|
POSTGRES_NSUID=100070
|
|
|
|
POSTGRES_NSGID=100070
|
|
|
|
SAHANA_UID=103
|
|
|
|
SAHANA_GID=104
|
|
|
|
SAHANA_NSUID=100103
|
|
|
|
SAHANA_NSGID=100104
|
|
|
|
|
2019-10-05 15:49:29 +02:00
|
|
|
# Create Postgres instance
|
2020-02-09 15:56:37 +01:00
|
|
|
mkdir -p ${VOLUME_DIR}/postgres_data
|
|
|
|
chown -R ${POSTGRES_NSUID}:${POSTGRES_NSGID} ${VOLUME_DIR}/postgres_data
|
|
|
|
chmod 700 ${VOLUME_DIR}/postgres_data
|
|
|
|
spoc-container exec sahana-postgres -- initdb -D /var/lib/postgresql
|
2019-10-05 15:49:29 +02:00
|
|
|
|
|
|
|
# Configure Postgres
|
2020-02-09 15:56:37 +01:00
|
|
|
cp postgres_data/postgresql.conf ${VOLUME_DIR}/postgres_data/postgresql.conf
|
|
|
|
cp postgres_data/pg_hba.conf ${VOLUME_DIR}/postgres_data/pg_hba.conf
|
2017-09-21 21:12:29 +02:00
|
|
|
|
2017-06-25 20:49:41 +02:00
|
|
|
# Create PostgreSQL user and database
|
2019-06-05 18:55:15 +02:00
|
|
|
export SAHANA_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
|
2020-02-09 15:56:37 +01:00
|
|
|
spoc-container start sahana-postgres
|
|
|
|
envsubst <createdb.sql | spoc-container exec sahana-postgres -- psql
|
2018-01-27 22:26:37 +01:00
|
|
|
|
|
|
|
# Prepare persistent directory structure
|
2020-02-09 15:56:37 +01:00
|
|
|
mkdir -p ${VOLUME_DIR}/sahana_data/databases ${VOLUME_DIR}/sahana_data/uploads
|
|
|
|
chown -R ${SAHANA_NSUID}:${SAHANA_NSGID} ${VOLUME_DIR}/sahana_data
|
|
|
|
cp -rp ${LAYER_DIR}/sahana_0.0.1-200207/srv/web2py/applications/eden/models ${VOLUME_DIR}/sahana_conf
|
2017-06-25 20:49:41 +02:00
|
|
|
|
2018-01-27 22:26:37 +01:00
|
|
|
# Copy Spotter template
|
2020-02-09 15:56:37 +01:00
|
|
|
cp -r sahana_data/Spotter ${VOLUME_DIR}/sahana_data/
|
|
|
|
chown -R ${SAHANA_NSUID}:${SAHANA_NSGID} ${VOLUME_DIR}/sahana_data
|
2017-06-25 20:49:41 +02:00
|
|
|
|
|
|
|
# Configure Sahana
|
2019-06-05 18:55:15 +02:00
|
|
|
export SAHANA_HMAC=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
|
2017-09-14 21:56:09 +02:00
|
|
|
export SAHANA_ADMIN_USER=admin@example.com
|
2019-06-05 18:55:15 +02:00
|
|
|
export SAHANA_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
|
2020-02-09 15:56:37 +01:00
|
|
|
envsubst <sahana_conf/000_config.py >${VOLUME_DIR}/sahana_conf/000_config.py
|
|
|
|
envsubst <sahana_data/Spotter/masterUsers.csv >${VOLUME_DIR}/sahana_data/Spotter/masterUsers.csv
|
|
|
|
cp sahana_conf/00_settings.py ${VOLUME_DIR}/sahana_conf/00_settings.py
|
|
|
|
chown -R ${SAHANA_NSUID}:${SAHANA_NSGID} ${VOLUME_DIR}/sahana_conf ${VOLUME_DIR}/sahana_data
|
2017-06-25 20:49:41 +02:00
|
|
|
|
|
|
|
# Populate database
|
2020-02-09 15:56:37 +01:00
|
|
|
spoc-container exec -u sahana sahana -- sh -c 'cd /srv/web2py; ./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py'
|
2017-06-25 20:49:41 +02:00
|
|
|
|
2017-09-26 12:52:05 +02:00
|
|
|
# Set "production values" (increases performance) only if the DEBUG environment variable is not set
|
|
|
|
if [ ${DEBUG:-0} -eq 0 ]; then
|
2020-02-09 15:56:37 +01:00
|
|
|
sed -i 's/settings.base.migrate = True/settings.base.migrate = False/' ${VOLUME_DIR}/sahana_conf/000_config.py
|
|
|
|
sed -i 's/settings.base.debug = True/settings.base.debug = False/' ${VOLUME_DIR}/sahana_conf/000_config.py
|
|
|
|
sed -i 's/#settings.base.prepopulate = 0/settings.base.prepopulate = 0/' ${VOLUME_DIR}/sahana_conf/000_config.py
|
2017-09-13 13:17:38 +02:00
|
|
|
fi
|
2018-07-15 21:55:35 +02:00
|
|
|
|
2018-09-20 15:45:00 +02:00
|
|
|
# Install config update script
|
2020-02-09 15:56:37 +01:00
|
|
|
cp update-conf.sh ${VOLUME_DIR}/update-conf.sh
|
2018-09-20 15:45:00 +02:00
|
|
|
|
2019-10-05 15:49:29 +02:00
|
|
|
# Stop services required for setup
|
2020-02-09 15:56:37 +01:00
|
|
|
spoc-container stop sahana-postgres
|
2018-10-28 19:50:35 +01:00
|
|
|
|
2018-11-03 15:53:51 +01:00
|
|
|
# Register application
|
2020-02-09 15:56:37 +01:00
|
|
|
#vmmgr register-app sahana sahana "${SAHANA_ADMIN_USER}" "${SAHANA_ADMIN_PWD}"
|