forked from yonderHub/docker-postgis-pgrouting
-
Notifications
You must be signed in to change notification settings - Fork 3
/
start.sh
28 lines (21 loc) · 835 Bytes
/
start.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
#!/bin/bash
DATADIR="/var/lib/postgresql/9.1/main"
CONF="/etc/postgresql/9.1/main/postgresql.conf"
POSTGRES="/usr/lib/postgresql/9.1/bin/postgres"
INITDB="/usr/lib/postgresql/9.1/bin/initdb"
# test if DATADIR is existent
if [ ! -d $DATADIR ]; then
echo "Creating Postgres data at $DATADIR"
mkdir -p $DATADIR
fi
chown -R postgres.postgres $DATADIR
# test if DATADIR has content
if [ ! "$(ls -A $DATADIR)" ]; then
echo "Initializing Postgres Database at $DATADIR"
chown -R postgres $DATADIR
su postgres sh -c "$INITDB $DATADIR"
su postgres sh -c "$POSTGRES --single -D $DATADIR -c config_file=$CONF" <<< "CREATE USER $USERNAME WITH SUPERUSER PASSWORD '$PASS';"
fi
trap "echo \"Sending SIGTERM to postgres\"; killall -s SIGTERM postgres" SIGTERM
su postgres sh -c "$POSTGRES -D $DATADIR -c config_file=$CONF" &
wait $!