forked from sebastiangeiger/docker-postgresql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
startup.sh
21 lines (21 loc) · 1.08 KB
/
startup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash
set -ex
if [ ! -d /var/lib/postgresql/9.3/main ]; then
echo "Initial startup"
mkdir -p /var/lib/postgresql/9.3/main
chmod 0700 /var/lib/postgresql/9.3/main
chown postgres /var/lib/postgresql/9.3/main
su postgres -c "/usr/lib/postgresql/9.3/bin/initdb --pgdata /var/lib/postgresql/9.3/main"
su postgres -c "/usr/lib/postgresql/9.3/bin/pg_ctl -D /var/lib/postgresql/9.3/main -o '-c config_file=/etc/postgresql/9.3/main/postgresql.conf' start"
sleep 10
if [ $DB_USER == "postgres" ]; then
echo "ALTER USER postgres with encrypted password '$DB_PASSWORD';" | su postgres -c psql
else
echo "CREATE USER $DB_USER WITH SUPERUSER PASSWORD '$DB_PASSWORD';" | su postgres -c psql
fi
# su postgres -c "createdb -O docker docker" NOT USEFUL
su postgres -c "/usr/lib/postgresql/9.3/bin/pg_ctl -D /var/lib/postgresql/9.3/main -o '-c config_file=/etc/postgresql/9.3/main/postgresql.conf' stop"
sleep 10
fi
echo "Regular startup"
su postgres -c "/usr/lib/postgresql/9.3/bin/postgres -D /var/lib/postgresql/9.3/main -c config_file=/etc/postgresql/9.3/main/postgresql.conf"