-
-
Notifications
You must be signed in to change notification settings - Fork 69
/
configure.sh
executable file
·76 lines (63 loc) · 1.95 KB
/
configure.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
# Sets up various stuff in Docker Container: database and Plugins
echo "START /configure.sh"
source /venv/bin/activate .
# Make sure PYTHONPATH includes GeoHealthCheck
export PYTHONPATH=/GeoHealthCheck/GeoHealthCheck:$PYTHONPATH
# Determine database type from DB URI
DB_TYPE=$(echo ${SQLALCHEMY_DATABASE_URI} | cut -f1 -d:)
echo "Using DB_TYPE=${DB_TYPE}"
# Create DB shorthand
function create_db() {
pushd /GeoHealthCheck/
paver create -u ${ADMIN_NAME} -p ${ADMIN_PWD} -e ${ADMIN_EMAIL}
popd
}
# Init actions per DB type
case ${DB_TYPE} in
sqlite)
if [ ! -f /GeoHealthCheck/DB/data.db ]
then
echo "Creating SQLite DB tables..."
create_db
else
echo "NOT creating SQLite DB tables..."
fi
;;
postgresql)
# format: postgresql://user:pw@host:5432/db
# Bit tricky, may use awk, but cut out DB elements from URI
DB_NAME=$(echo ${SQLALCHEMY_DATABASE_URI} | cut -f4 -d/)
DB_PASSWD_HOST=$(echo ${SQLALCHEMY_DATABASE_URI} | cut -f3 -d:)
DB_HOST=$(echo ${DB_PASSWD_HOST} | cut -f2 -d@)
DB_PASSWD=$(echo ${DB_PASSWD_HOST} | cut -f1 -d@)
DB_USER_SLASH=$(echo ${SQLALCHEMY_DATABASE_URI} | cut -f2 -d:)
DB_USER=$(echo ${DB_USER_SLASH} | cut -f3 -d/)
export PGPASSWORD=${DB_PASSWD}
# We need to wait until PG Container available
echo "Check if Postgres is avail/ready..."
until pg_isready -h "${DB_HOST}"; do
echo "Exit code=$? - Postgres not ready - sleeping"
sleep 1
done
# Check if we need to create DB tables
echo "Postgres is up - check if DB populated"
if ! psql -h "${DB_HOST}" -U "${DB_USER}" -c 'SELECT COUNT(*) FROM resource' ${DB_NAME}
then
echo "Creating Postgres DB tables..."
create_db
else
echo "Postgres DB already populated"
fi
;;
*)
echo "Unknown database type ${DB_TYPE}, exiting"
exit -1
;;
esac
# Copy possible mounted Plugins into app tree
if [ -d /plugins ]
then
cp -ar /plugins/* /GeoHealthCheck/GeoHealthCheck/plugins/
fi
echo "END /configure.sh"