From 089c3eaf1ac27f2a9438901827568f32ae87229c Mon Sep 17 00:00:00 2001 From: Anentropic Date: Sat, 7 Nov 2015 21:46:50 +0000 Subject: [PATCH] start temporary server in local-only mode, poll instead of blind wait, preserve pid 1 --- Dockerfile | 2 +- start-postgis.sh | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 48ee356..ffb74be 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,7 +23,7 @@ RUN apt-get -y install ca-certificates rpl pwgen # The following packages have unmet dependencies: # postgresql-9.3-postgis-2.1 : Depends: libgdal1h (>= 1.9.0) but it is not going to be installed # Recommends: postgis but it is not going to be installed -RUN apt-get install -y postgresql-9.4-postgis-2.1 postgis +RUN apt-get install -y postgresql-9.4-postgis-2.1 postgis netcat ADD postgres.conf /etc/supervisor/conf.d/postgres.conf # Open port 5432 so linked containers can see them diff --git a/start-postgis.sh b/start-postgis.sh index f085e3f..802b799 100755 --- a/start-postgis.sh +++ b/start-postgis.sh @@ -7,6 +7,7 @@ CONF="/etc/postgresql/9.4/main/postgresql.conf" POSTGRES="/usr/lib/postgresql/9.4/bin/postgres" INITDB="/usr/lib/postgresql/9.4/bin/initdb" SQLDIR="/usr/share/postgresql/9.4/contrib/postgis-2.1/" +LOCALONLY="-c listen_addresses='127.0.0.1, ::1'" # /etc/ssl/private can't be accessed from within container for some reason # (@andrewgodwin says it's something AUFS related) - taken from https://github.com/orchardup/docker-postgresql/blob/master/Dockerfile @@ -72,11 +73,15 @@ su - postgres -c "$POSTGRES --single -D $DATADIR -c config_file=$CONF <<< \"CREA trap "echo \"Sending SIGTERM to postgres\"; killall -s SIGTERM postgres" SIGTERM -su - postgres -c "$POSTGRES -D $DATADIR -c config_file=$CONF &" +su - postgres -c "$POSTGRES -D $DATADIR -c config_file=$CONF $LOCALONLY &" -# Wait for the db to start up before trying to use it.... +# wait for postgres to come up +until `nc -z 127.0.0.1 5432`; do + echo "$(date) - waiting for postgres (localhost-only)..." + sleep 1 +done +echo "postgres ready" -sleep 10 RESULT=`su - postgres -c "psql -l | grep postgis | wc -l"` if [[ ${RESULT} == '1' ]] @@ -126,4 +131,4 @@ su - postgres -c "psql -l" PID=`cat /var/run/postgresql/9.4-main.pid` kill -9 ${PID} echo "Postgres initialisation process completed .... restarting in foreground" -su - postgres -c "$POSTGRES -D $DATADIR -c config_file=$CONF" +exec su - postgres -c "$POSTGRES -D $DATADIR -c config_file=$CONF"