pretty clean
1 file changed, +11 -6
+11-6docker-entrypoint.sh
| @@ -1,20 +1,25 @@ | ||
| 1 | 1 | #!/bin/sh |
| 2 | 2 | |
| 3 | +if [ ! -d /var/lib/postgresql/data ];then | |
| 4 | + mkdir /var/lib/postgresql/data | |
| 5 | +fi | |
| 6 | + | |
| 3 | 7 | # take care of postgres business |
| 4 | -chown -R postgres:postgres /var/lib/postgresql | |
| 8 | +chmod 700 /var/lib/postgresql/data | |
| 9 | +chown -R postgres:postgres /var/lib/postgresql/data | |
| 5 | 10 | su -s /bin/sh postgres <<EOF |
| 6 | 11 | cd |
| 7 | -if [ ! -d data ];then | |
| 12 | +if [ -z $(ls /var/lib/postgresql/data) ];then | |
| 8 | 13 | echo 'No data found, initializing postgres.' |
| 9 | - mkdir data | |
| 10 | - chmod 700 data | |
| 11 | - initdb -D data > /dev/null 2> /dev/null | |
| 14 | + initdb -D data > /dev/null > /dev/null 2>&1 | |
| 12 | 15 | echo "host all all 0.0.0.0/0 md5" >> /var/lib/postgresql/data/pg_hba.conf |
| 13 | 16 | echo "listen_addresses='*'" >> /var/lib/postgresql/data/postgresql.conf |
| 14 | 17 | sed -i '/unix_socket_directories/d' /var/lib/postgresql/data/postgresql.conf |
| 15 | 18 | echo 'Postgres initialized' |
| 19 | +else | |
| 20 | + echo "Postgres data found, skipping initialization" | |
| 16 | 21 | fi |
| 17 | -pg_ctl start -D /var/lib/postgresql/data > /dev/null | |
| 22 | +pg_ctl start -D /var/lib/postgresql/data > /dev/null 2>&1 | |
| 18 | 23 | echo 'Postgres Ready' |
| 19 | 24 | EOF |
| 20 | 25 |