From 1250909c4ea6997b08c4cadfb656b09198f215b3 Mon Sep 17 00:00:00 2001 From: Tim Sutton Date: Thu, 8 Feb 2018 22:23:54 +0200 Subject: [PATCH] Fixes for pg 10 to start nicely --- run-postgis-docker.sh | 16 +++++++++++----- start-postgis.sh | 28 ++++++++++++++++++---------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/run-postgis-docker.sh b/run-postgis-docker.sh index faaa67b..9b6c05f 100755 --- a/run-postgis-docker.sh +++ b/run-postgis-docker.sh @@ -1,6 +1,7 @@ #!/bin/bash # Commit and redeploy the user map container +set -x usage() { cat << EOF @@ -18,11 +19,12 @@ OPTIONS: -l local port (defaults to 25432) -u Postgres user name (defaults to 'docker') -p Postgres password (defaults to 'docker') - -d database name (defaults to 'gis') + -d database cluster path (defaults to debian package defaults) + -z database name (defaults to 'gis') EOF } -while getopts ":h:n:v:l:u:p:d:" OPTION +while getopts ":h:n:v:l:u:p:d:z:" OPTION do case $OPTION in n) @@ -32,10 +34,10 @@ do VOLUME=${OPTARG} ;; l) - LOCALPORT=${optarg} + LOCALPORT=${OPTARG} ;; u) - PGUSER=${optarg} + PGUSER=${OPTARG} ;; p) PGPASSWORD=${OPTARG} @@ -43,7 +45,10 @@ do d) DATADIR=${OPTARG} ;; - *) + z) + DBNAME=${OPTARG} + ;; + \?) usage exit 1 ;; @@ -86,6 +91,7 @@ CMD="docker run --name="${CONTAINER_NAME}" \ -e POSTGRES_USER=${PGUSER} \ -e POSTGRES_PASS=${PGPASSWORD} \ -e DATADIR=${DATADIR} \ + -e POSTGRES_DBNAME=${DBNAME} \ -d -t \ ${VOLUME_OPTION} \ -p "${LOCALPORT}:5432" \ diff --git a/start-postgis.sh b/start-postgis.sh index 20b9002..da754de 100755 --- a/start-postgis.sh +++ b/start-postgis.sh @@ -2,11 +2,11 @@ # This script will run as the postgres user due to the Dockerfile USER directive -DATADIR="/var/lib/postgresql/10.0/main" -CONF="/etc/postgresql/10.0/main/postgresql.conf" -POSTGRES="/usr/lib/postgresql/10.0/bin/postgres" -INITDB="/usr/lib/postgresql/10.0/bin/initdb" -SQLDIR="/usr/share/postgresql/10.0/contrib/postgis-2.2/" +DATADIR="/var/lib/postgresql/10/main" +CONF="/etc/postgresql/10/main/postgresql.conf" +POSTGRES="/usr/lib/postgresql/10/bin/postgres" +INITDB="/usr/lib/postgresql/10/bin/initdb" +SQLDIR="/usr/share/postgresql/10/contrib/postgis-2.2/" LOCALONLY="-c listen_addresses='127.0.0.1, ::1'" # /etc/ssl/private can't be accessed from within container for some reason @@ -18,12 +18,12 @@ rm -r /etc/ssl mv /tmp/ssl-copy /etc/ssl # Needed under debian, wasnt needed under ubuntu -mkdir -p /var/run/postgresql/10.0-main.pg_stat_tmp -chmod 0777 /var/run/postgresql/10.0-main.pg_stat_tmp +mkdir -p /var/run/postgresql/10-main.pg_stat_tmp +chmod 0777 /var/run/postgresql/10-main.pg_stat_tmp # test if DATADIR is existent if [ ! -d $DATADIR ]; then - echo "Creating Postgres data at $DATADIR" + echo "Creating Postgres data directory at $DATADIR" mkdir -p $DATADIR fi # needs to be done as root: @@ -139,14 +139,22 @@ fi # This should show up in docker logs afterwards su - postgres -c "psql -l" -PID=`cat /var/run/postgresql/10.0-main.pid` +echo "Lock files" +echo "------------------------" +ls /var/run/postgresql/ +echo "------------------------" + +PID=`cat /var/run/postgresql/10-main.pid` kill -TERM ${PID} # Wait for background postgres main process to exit -while [ "$(ls -A /var/run/postgresql/10.0-main.pid 2>/dev/null)" ]; do +while [ "$(ls -A /var/run/postgresql/10-main.pid 2>/dev/null)" ]; do sleep 1 done +# Remove the lock file that may have been left behind in the above step +rm /var/run/postgresql/*.pid + echo "Postgres initialisation process completed .... restarting in foreground" SETVARS="POSTGIS_ENABLE_OUTDB_RASTERS=1 POSTGIS_GDAL_ENABLED_DRIVERS=ENABLE_ALL" su - postgres -c "$SETVARS $POSTGRES -D $DATADIR -c config_file=$CONF"