-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit-db.sh
executable file
·39 lines (33 loc) · 1.11 KB
/
init-db.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
#!/bin/bash
# MUST BE EXECUTED AS postgres USER
# See: https://trac.osgeo.org/postgis/wiki/UsersWikiPostGIS3UbuntuPGSQLApt
pg_lsclusters 14 main start
service postgresql restart
# Wait for the postgres database to startup
echo "Waiting for postgres server..."
# Await PostGreSQL server to become available
RETRIES=20
while [ "$RETRIES" -gt 0 ]
do
echo "Waiting for postgres: pg_isready -d ${POSTGRES_NAME} -h ${POSTGRES_HOST} -p ${POSTGRES_PORT} -U ${POSTGRES_USER}"
PG_STATUS="$(pg_isready -d ${POSTGRES_NAME} -h ${POSTGRES_HOST} -p ${POSTGRES_PORT} -U ${POSTGRES_USER})"
PG_EXIT=$(echo $?)
if [ "$PG_EXIT" = "0" ];
then
RETRIES=0
fi
sleep 0.5
done
echo "Postgres server is up!"
# Create the database
echo "Creating database ${POSTGRES_DB}..."
createdb ${POSTGRES_DB} -O ${POSTGRES_USER}
# Load PostGIS into $POSTGRES_DB
for DB in "$POSTGRES_DB" "${@}"; do
psql --dbname="$DB" -c "
CREATE EXTENSION IF NOT EXISTS postgis;
"
done
# Set the password for the postgres user
echo "Setting password for postgres user..."
psql -c "ALTER USER ${POSTGRES_USER} WITH PASSWORD '${POSTGRES_PASSWORD}';"