mirror of
https://github.com/nextcloud/all-in-one.git
synced 2025-02-25 06:14:38 +08:00
Merge pull request #1118 from nextcloud/enh/1073/add-db-check
add a check for init-user-db.sh
This commit is contained in:
commit
d25c74e382
2 changed files with 24 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue