#!/bin/sh set -ev cd $(realpath $(dirname "${0}"))/install # Create Postgres instance mkdir -p /srv/sahana/postgres_data chown -R 105432:105432 /srv/sahana/postgres_data chmod 700 /srv/sahana/postgres_data lxc-execute -n sahana-postgres -- initdb -D /var/lib/postgresql # Configure Postgres cp postgres_data/postgresql.conf /srv/sahana/postgres_data/postgresql.conf cp postgres_data/pg_hba.conf /srv/sahana/postgres_data/pg_hba.conf # Create PostgreSQL user and database export SAHANA_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=') service sahana-postgres start envsubst /srv/sahana/sahana_conf/000_config.py envsubst /srv/sahana/sahana_data/Spotter/masterUsers.csv cp sahana_conf/00_settings.py /srv/sahana/sahana_conf/00_settings.py chown -R 108001:108001 /srv/sahana/sahana_conf chown -R 108001:108001 /srv/sahana/sahana_data # Populate database lxc-execute -u 8001 -g 8001 sahana -- sh -c 'cd /srv/web2py; ./web2py.py -S eden -M -R applications/eden/static/scripts/tools/noop.py' # Set "production values" (increases performance) only if the DEBUG environment variable is not set if [ ${DEBUG:-0} -eq 0 ]; then sed -i 's/settings.base.migrate = True/settings.base.migrate = False/' /srv/sahana/sahana_conf/000_config.py sed -i 's/settings.base.debug = True/settings.base.debug = False/' /srv/sahana/sahana_conf/000_config.py sed -i 's/#settings.base.prepopulate = 0/settings.base.prepopulate = 0/' /srv/sahana/sahana_conf/000_config.py fi # Install config update script cp update-conf.sh /srv/sahana/update-conf.sh # Stop services required for setup service sahana-postgres stop # Register application vmmgr register-app sahana sahana "${SAHANA_ADMIN_USER}" "${SAHANA_ADMIN_PWD}"