From 9b3c6a7dbd5a5da383c6eb33fdf510aea5535907 Mon Sep 17 00:00:00 2001 From: Andres Villarroel Date: Fri, 20 Jan 2017 10:32:24 -0500 Subject: [PATCH 1/4] Allow changing the default database name (#50) --- README.md | 5 +++-- start-postgis.sh | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 15359ab..798d8f6 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ differentiates itself by: * provides ssl support out of the box * connections are restricted to the docker subnet * template_postgis database template is created for you -* a database 'gis' is created for you so you can use this container 'out of the +* a default database 'gis' is created for you so you can use this container 'out of the box' when it runs with e.g. QGIS We will work to add more security features to this container in the future with @@ -85,10 +85,11 @@ sudo docker run --name "postgis" -p 25432:5432 -d -t kartoza/postgis ## Environment variables You can also use the following environment variables to pass a -user name and password. +user name, password and/or default database name. * -e POSTGRES_USER= * -e POSTGRES_PASS= +* -e POSTGRES_DBNAME= These will be used to create a new superuser with your preferred credentials. If these are not specified then the postgresql diff --git a/start-postgis.sh b/start-postgis.sh index cee1e8b..bb7af23 100755 --- a/start-postgis.sh +++ b/start-postgis.sh @@ -55,6 +55,10 @@ fi if [ -z "$POSTGRES_PASS" ]; then POSTGRES_PASS=docker fi +# Set a default database name +if [ -z "$POSTGRES_DBNAME" ]; then + POSTGRES_DBNAME=gis +fi # Enable hstore and topology by default if [ -z "$HSTORE" ]; then HSTORE=true @@ -129,7 +133,7 @@ else su - postgres -c "psql template_postgis -f $SQLDIR/legacy_gist.sql" # Create a default db called 'gis' that you can use to get up and running quickly # It will be owned by the docker db user - su - postgres -c "createdb -O $POSTGRES_USER -T template_postgis gis" + su - postgres -c "createdb -O $POSTGRES_USER -T template_postgis $POSTGRES_DBNAME" fi # This should show up in docker logs afterwards su - postgres -c "psql -l" From d1644703cf318b24e44d3b113457376d807af274 Mon Sep 17 00:00:00 2001 From: Tim Sutton Date: Mon, 27 Mar 2017 06:30:48 +0200 Subject: [PATCH 2/4] Commented out legacy scripts since it seems they are removed in 2.2 --- start-postgis.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/start-postgis.sh b/start-postgis.sh index bb7af23..7da3f20 100755 --- a/start-postgis.sh +++ b/start-postgis.sh @@ -128,9 +128,10 @@ else fi # Needed when importing old dumps using e.g ndims for constraints - echo "Loading legacy sql" - su - postgres -c "psql template_postgis -f $SQLDIR/legacy_minimal.sql" - su - postgres -c "psql template_postgis -f $SQLDIR/legacy_gist.sql" + # commented out these lines since it seems these scripts are removed in Postgis 2.2 + #echo "Loading legacy sql" + #su - postgres -c "psql template_postgis -f $SQLDIR/legacy_minimal.sql" + #su - postgres -c "psql template_postgis -f $SQLDIR/legacy_gist.sql" # Create a default db called 'gis' that you can use to get up and running quickly # It will be owned by the docker db user su - postgres -c "createdb -O $POSTGRES_USER -T template_postgis $POSTGRES_DBNAME" From b7633a0dc4dbdf2a7acb8eb9248412a258a2d984 Mon Sep 17 00:00:00 2001 From: Tim Sutton Date: Mon, 27 Mar 2017 06:34:38 +0200 Subject: [PATCH 3/4] 9.5 2.2 (#59) * Allow changing the default database name (#50) * Commented out legacy scripts since it seems they are removed in 2.2 --- README.md | 5 +++-- start-postgis.sh | 13 +++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 15359ab..798d8f6 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ differentiates itself by: * provides ssl support out of the box * connections are restricted to the docker subnet * template_postgis database template is created for you -* a database 'gis' is created for you so you can use this container 'out of the +* a default database 'gis' is created for you so you can use this container 'out of the box' when it runs with e.g. QGIS We will work to add more security features to this container in the future with @@ -85,10 +85,11 @@ sudo docker run --name "postgis" -p 25432:5432 -d -t kartoza/postgis ## Environment variables You can also use the following environment variables to pass a -user name and password. +user name, password and/or default database name. * -e POSTGRES_USER= * -e POSTGRES_PASS= +* -e POSTGRES_DBNAME= These will be used to create a new superuser with your preferred credentials. If these are not specified then the postgresql diff --git a/start-postgis.sh b/start-postgis.sh index cee1e8b..7da3f20 100755 --- a/start-postgis.sh +++ b/start-postgis.sh @@ -55,6 +55,10 @@ fi if [ -z "$POSTGRES_PASS" ]; then POSTGRES_PASS=docker fi +# Set a default database name +if [ -z "$POSTGRES_DBNAME" ]; then + POSTGRES_DBNAME=gis +fi # Enable hstore and topology by default if [ -z "$HSTORE" ]; then HSTORE=true @@ -124,12 +128,13 @@ else fi # Needed when importing old dumps using e.g ndims for constraints - echo "Loading legacy sql" - su - postgres -c "psql template_postgis -f $SQLDIR/legacy_minimal.sql" - su - postgres -c "psql template_postgis -f $SQLDIR/legacy_gist.sql" + # commented out these lines since it seems these scripts are removed in Postgis 2.2 + #echo "Loading legacy sql" + #su - postgres -c "psql template_postgis -f $SQLDIR/legacy_minimal.sql" + #su - postgres -c "psql template_postgis -f $SQLDIR/legacy_gist.sql" # Create a default db called 'gis' that you can use to get up and running quickly # It will be owned by the docker db user - su - postgres -c "createdb -O $POSTGRES_USER -T template_postgis gis" + su - postgres -c "createdb -O $POSTGRES_USER -T template_postgis $POSTGRES_DBNAME" fi # This should show up in docker logs afterwards su - postgres -c "psql -l" From 08e8c36654b6d1f3204577c20391d6e4b380fc27 Mon Sep 17 00:00:00 2001 From: AndreLobato Date: Mon, 27 Mar 2017 17:37:08 +1300 Subject: [PATCH 4/4] Improve start (#57) * Make initial dir optional * Improve termination of background initial process #56 --- start-postgis.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/start-postgis.sh b/start-postgis.sh index 7da3f20..60fbdd8 100755 --- a/start-postgis.sh +++ b/start-postgis.sh @@ -18,7 +18,7 @@ rm -r /etc/ssl mv /tmp/ssl-copy /etc/ssl # Needed under debian, wasnt needed under ubuntu -mkdir /var/run/postgresql/9.5-main.pg_stat_tmp +mkdir -p /var/run/postgresql/9.5-main.pg_stat_tmp chmod 0777 /var/run/postgresql/9.5-main.pg_stat_tmp # test if DATADIR is existent @@ -140,7 +140,13 @@ fi su - postgres -c "psql -l" PID=`cat /var/run/postgresql/9.5-main.pid` -kill -9 ${PID} +kill -TERM ${PID} + +# Wait for background postgres main process to exit +while [ "$(ls -A /var/run/postgresql/9.5-main.pid 2>/dev/null)" ]; do + sleep 1 +done + 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"