mirror of
https://github.com/nextcloud/all-in-one.git
synced 2025-01-04 13:01:51 +08:00
Merge pull request #218 from nextcloud/enh/noid/fix-database-connection
fix the database connection
This commit is contained in:
commit
5bc10a56ed
4 changed files with 29 additions and 6 deletions
|
@ -6,6 +6,16 @@ while ! nc -z "$POSTGRES_HOST" 5432; do
|
||||||
sleep 5
|
sleep 5
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Use the correct Postgres username
|
||||||
|
POSTGRES_USER="oc_$POSTGRES_USER"
|
||||||
|
export POSTGRES_USER
|
||||||
|
|
||||||
|
# Fix false database connection on old instances
|
||||||
|
if [ -f "/var/www/html/config/config.php" ] && sleep 2 && psql -d "postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST:5432/$POSTGRES_DB" -c "select now()"; then
|
||||||
|
sed -i "s|'dbuser'.*=>.*$|'dbuser' => '$POSTGRES_USER',|" /var/www/html/config/config.php
|
||||||
|
sed -i "s|'dbpassword'.*=>.*$|'dbpassword' => '$POSTGRES_PASSWORD',|" /var/www/html/config/config.php
|
||||||
|
fi
|
||||||
|
|
||||||
# Run original entrypoint
|
# Run original entrypoint
|
||||||
if ! bash /entrypoint.sh; then
|
if ! bash /entrypoint.sh; then
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
@ -17,7 +17,9 @@ RUN set -ex; \
|
||||||
chown -R postgres:postgres "$PGDATA"
|
chown -R postgres:postgres "$PGDATA"
|
||||||
|
|
||||||
COPY start.sh /usr/bin/
|
COPY start.sh /usr/bin/
|
||||||
RUN chmod +x /usr/bin/start.sh
|
COPY init-user-db.sh /docker-entrypoint-initdb.d/
|
||||||
|
RUN chmod +x /usr/bin/start.sh; \
|
||||||
|
chmod +xr /docker-entrypoint-initdb.d/init-user-db.sh
|
||||||
|
|
||||||
RUN mkdir /mnt/data; \
|
RUN mkdir /mnt/data; \
|
||||||
chown postgres:postgres /mnt/data;
|
chown postgres:postgres /mnt/data;
|
||||||
|
|
9
Containers/postgresql/init-user-db.sh
Normal file
9
Containers/postgresql/init-user-db.sh
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#!/bin/bash
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
|
||||||
|
CREATE USER "oc_$POSTGRES_USER" WITH PASSWORD "$POSTGRES_PASSWORD";
|
||||||
|
GRANT ALL PRIVILEGES ON DATABASE "$POSTGRES_DB" TO "oc_$POSTGRES_USER";
|
||||||
|
EOSQL
|
||||||
|
|
||||||
|
set +ex
|
|
@ -18,11 +18,13 @@ if ! [ -w "$DUMP_DIR" ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# # Delete the datadir once (needed for the migration from debian to alpine)
|
# Delete the datadir once (needed for setting the correct credentials on old instances once)
|
||||||
# if ! [ -f "$DUMP_DIR/initial-cleanup-done" ]; then
|
if ! [ -f "$DUMP_DIR/export.failed" ] && ! [ -f "$DUMP_DIR/initial-cleanup-done" ]; then
|
||||||
# rm -rf "${DATADIR:?}/"*
|
set -ex
|
||||||
# touch "$DUMP_DIR/initial-cleanup-done"
|
rm -rf "${DATADIR:?}/"*
|
||||||
# fi
|
touch "$DUMP_DIR/initial-cleanup-done"
|
||||||
|
set +ex
|
||||||
|
fi
|
||||||
|
|
||||||
# Test if some things match
|
# Test if some things match
|
||||||
# shellcheck disable=SC2235
|
# shellcheck disable=SC2235
|
||||||
|
|
Loading…
Reference in a new issue