From abb414129af073db58d11d04f331f26dd9a96d2e Mon Sep 17 00:00:00 2001 From: szaimen Date: Mon, 5 Sep 2022 14:04:32 +0200 Subject: [PATCH] add a check for init-user-db.sh Signed-off-by: szaimen --- Containers/postgresql/init-user-db.sh | 4 ++++ Containers/postgresql/start.sh | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/Containers/postgresql/init-user-db.sh b/Containers/postgresql/init-user-db.sh index 1f09770b..5d4474a2 100644 --- a/Containers/postgresql/init-user-db.sh +++ b/Containers/postgresql/init-user-db.sh @@ -1,9 +1,13 @@ #!/bin/bash set -ex +touch /mnt/data/initdb.failed + psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL CREATE USER "oc_$POSTGRES_USER" WITH PASSWORD '$POSTGRES_PASSWORD' CREATEDB; ALTER DATABASE "$POSTGRES_DB" OWNER TO "oc_$POSTGRES_USER"; EOSQL +rm /mnt/data/initdb.failed + set +ex diff --git a/Containers/postgresql/start.sh b/Containers/postgresql/start.sh index b2e25a1b..b8563b27 100644 --- a/Containers/postgresql/start.sh +++ b/Containers/postgresql/start.sh @@ -18,6 +18,16 @@ if ! [ -w "$DUMP_DIR" ]; then exit 1 fi +# Check if initdb was successful +if [ -f "/mnt/data/initdb.failed" ]; then + echo "It seems like initializing the database was unsuccessful." + echo "Most likely the timezone is not a valid one." + echo "Please restore a backup, change the timezone to a valid one and try again." + echo "If this is a new instance, clean it properly by following https://github.com/nextcloud/all-in-one#how-to-properly-reset-the-instance" + echo "Afterwards feel free to try again with a valid timezone." + exit 1 +fi + # Delete the datadir once (needed for setting the correct credentials on old instances once) if ! [ -f "$DUMP_DIR/export.failed" ] && ! [ -f "$DUMP_DIR/initial-cleanup-done" ]; then set -ex @@ -58,6 +68,11 @@ if ( [ -f "$DATADIR/PG_VERSION" ] && [ "$PG_MAJOR" != "$(cat "$DATADIR/PG_VERSIO # Create new database exec docker-entrypoint.sh postgres & + # Exit if initdb failed + if [ -f "/mnt/data/initdb.failed" ]; then + exit 1 + fi + # Wait for creation while ! nc -z localhost 11000; do echo "Waiting for the database to start." @@ -124,6 +139,11 @@ trap 'true' SIGINT SIGTERM exec docker-entrypoint.sh postgres & wait $! +# Exit if initdb failed +if [ -f "/mnt/data/initdb.failed" ]; then + exit 1 +fi + # Continue with shutdown procedure: do database dump, etc. rm -f "$DUMP_FILE.temp" touch "$DUMP_DIR/export.failed"