2018-07-06 15:17:01 +00:00
#!/bin/bash
set -o nounset
set -o errexit
set -o pipefail
# == Vars
#
DB_MIGRATION_DIR = '/powerdns-admin/migrations'
2018-06-11 07:12:04 +00:00
2018-06-27 11:29:52 +00:00
# Wait for us to be able to connect to MySQL before proceeding
2018-07-06 15:17:01 +00:00
echo " ===> Waiting for $PDA_DB_HOST MySQL service "
2018-06-27 11:29:52 +00:00
until nc -zv \
$PDA_DB_HOST \
3306;
do
echo " MySQL ( $PDA_DB_HOST ) is unavailable - sleeping "
sleep 1
done
2018-07-06 15:17:01 +00:00
echo "===> DB management"
# Go in Workdir
2018-06-10 13:16:28 +00:00
cd /powerdns-admin
2018-06-13 04:05:53 +00:00
2018-07-06 15:17:01 +00:00
if [ ! -d " ${ DB_MIGRATION_DIR } " ] ; then
echo "---> Running DB Init"
flask db init --directory ${ DB_MIGRATION_DIR }
flask db migrate -m "Init DB" --directory ${ DB_MIGRATION_DIR }
flask db upgrade --directory ${ DB_MIGRATION_DIR }
./init_data.py
2018-06-11 07:12:04 +00:00
else
2018-07-06 15:17:01 +00:00
echo "---> Running DB Migration"
set +e
flask db migrate -m "Upgrade BD Schema" --directory ${ DB_MIGRATION_DIR }
flask db upgrade --directory ${ DB_MIGRATION_DIR }
set -e
2018-06-11 07:12:04 +00:00
fi
2018-08-25 17:12:58 +00:00
echo "===> Update PDNS API connection info"
mysql -h${ PDA_DB_HOST } -u${ PDA_DB_USER } -p${ PDA_DB_PASSWORD } ${ PDA_DB_NAME } -e " UPDATE setting SET value='http:// ${ PDNS_HOST } :8081' WHERE name='pdns_api_url'; "
mysql -h${ PDA_DB_HOST } -u${ PDA_DB_USER } -p${ PDA_DB_PASSWORD } ${ PDA_DB_NAME } -e " UPDATE setting SET value=' ${ PDNS_API_KEY } ' WHERE name='pdns_api_key'; "
2018-06-10 13:16:28 +00:00
2018-07-06 15:17:01 +00:00
echo "===> Assets management"
echo "---> Running Yarn"
chown -R www-data:www-data /powerdns-admin/app/static
chown -R www-data:www-data /powerdns-admin/node_modules
su -s /bin/bash -c 'yarn install --pure-lockfile' www-data
echo "---> Running Flask assets"
chown -R www-data:www-data /powerdns-admin/logs
su -s /bin/bash -c 'flask assets build' www-data
echo "===> Start supervisor"
2018-04-17 14:21:42 +00:00
/usr/bin/supervisord -c /etc/supervisord.conf