2018-04-21 22:30:25 +02:00
|
|
|
#!/bin/sh
|
2018-10-28 16:04:11 +01:00
|
|
|
set -ev
|
2018-04-21 22:30:25 +02:00
|
|
|
|
2019-09-27 11:28:00 +02:00
|
|
|
# Create Postgres instance
|
|
|
|
mkdir -p /srv/crisiscleanup/postgres_data
|
|
|
|
chown -R 105432:105432 /srv/crisiscleanup/postgres_data
|
|
|
|
chmod 700 /srv/crisiscleanup/postgres_data
|
|
|
|
lxc-execute -n crisiscleanup-postgres -- initdb -D /var/lib/postgresql
|
|
|
|
|
|
|
|
# Configure Postgres
|
|
|
|
cp postgres_data/postgresql.conf /srv/crisiscleanup/postgres_data/postgresql.conf
|
|
|
|
cp postgres_data/pg_hba.conf /srv/crisiscleanup/postgres_data/pg_hba.conf
|
2018-04-21 22:30:25 +02:00
|
|
|
|
|
|
|
# Create database
|
2019-06-05 18:55:15 +02:00
|
|
|
export CRISISCLEANUP_PWD=$(head -c 18 /dev/urandom | base64 | tr -d '+/=')
|
2019-11-30 22:11:38 +01:00
|
|
|
service lxc-crisiscleanup-postgres start
|
2019-09-27 11:28:00 +02:00
|
|
|
envsubst <createdb.sql | lxc-attach -u 5432 -g 5432 crisiscleanup-postgres -- psql
|
2018-04-21 22:30:25 +02:00
|
|
|
|
|
|
|
# Copy existing config files into persistent storage
|
2019-12-07 15:52:09 +01:00
|
|
|
lxchelper extract crisiscleanup /srv/crisiscleanup/config /srv/crisiscleanup/cc_conf
|
2018-04-21 22:30:25 +02:00
|
|
|
|
|
|
|
# Configure CrisisCleanup
|
|
|
|
export CRISISCLEANUP_ADMIN_USER="Admin"
|
|
|
|
export CRISISCLEANUP_ADMIN_EMAIL="admin@example.com"
|
2019-06-05 18:55:15 +02:00
|
|
|
export CRISISCLEANUP_ADMIN_PWD=$(head -c 12 /dev/urandom | base64 | tr -d '+/=')
|
2019-10-05 16:34:10 +02:00
|
|
|
envsubst <cc_conf/database.yml >/srv/crisiscleanup/cc_conf/database.yml
|
|
|
|
cp cc_conf/boot.rb /srv/crisiscleanup/cc_conf/boot.rb
|
|
|
|
cp cc_conf/initializers/devise.rb /srv/crisiscleanup/cc_conf/initializers/devise.rb
|
|
|
|
cp cc_conf/environments/production.rb /srv/crisiscleanup/cc_conf/environments/production.rb
|
2018-04-21 22:30:25 +02:00
|
|
|
|
|
|
|
# Populate database
|
2018-09-13 18:31:19 +02:00
|
|
|
lxc-execute crisiscleanup -- rake db:schema:load
|
2019-12-01 14:46:45 +01:00
|
|
|
envsubst <adminpwd.rb | lxc-execute crisiscleanup -- sh -c 'cd /srv/crisiscleanup; bin/rails console -e production'
|
2018-09-13 18:31:19 +02:00
|
|
|
|
2018-09-20 15:45:00 +02:00
|
|
|
# Install config update script
|
2019-09-27 11:28:00 +02:00
|
|
|
cp update-conf.sh /srv/crisiscleanup/update-conf.sh
|
2018-09-20 15:45:00 +02:00
|
|
|
|
2018-09-13 18:31:19 +02:00
|
|
|
# Stop services required for setup
|
2019-11-30 22:11:38 +01:00
|
|
|
service lxc-crisiscleanup-postgres stop
|
2018-10-28 19:50:35 +01:00
|
|
|
|
2018-11-03 15:53:51 +01:00
|
|
|
# Register application
|
2019-02-26 21:12:41 +01:00
|
|
|
vmmgr register-app crisiscleanup cc "${CRISISCLEANUP_ADMIN_EMAIL}" "${CRISISCLEANUP_ADMIN_PWD}"
|