allow to make wrong database intialization better debuggable

Signed-off-by: Simon L <szaimen@e.mail.de>
This commit is contained in:
Simon L 2022-12-29 00:41:29 +01:00
parent 4750fb228f
commit ee50e9147d
2 changed files with 15 additions and 1 deletions

View file

@ -1,9 +1,13 @@
#!/bin/bash
set -ex
touch "$DUMP_DIR/initialization.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 "$DUMP_DIR/initialization.failed"
set +ex

View file

@ -2,7 +2,7 @@
# Variables
DATADIR="/var/lib/postgresql/data"
DUMP_DIR="/mnt/data"
export DUMP_DIR="/mnt/data"
DUMP_FILE="$DUMP_DIR/database-dump.sql"
export PGPASSWORD="$POSTGRES_PASSWORD"
@ -27,6 +27,16 @@ if [ -f "$DUMP_DIR/import.failed" ]; then
exit 1
fi
# Don't start if initialization failed
if [ -f "$DUMP_DIR/initialization.failed" ]; then
echo "The database initialization failed. Most likely was a wrong timezone selected."
echo "The selected timezone is '$TZ'."
echo "Please check if it is in 'TZ database name' column of the timezone list: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List"
echo "For further clues on what went wrong, look at the logs above."
echo "You might start again from scratch by following https://github.com/nextcloud/all-in-one#how-to-properly-reset-the-instance and selecting a proper 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