mirror of
https://github.com/nextcloud/all-in-one.git
synced 2025-01-01 19:41:44 +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
|
||||
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
|
||||
if ! bash /entrypoint.sh; then
|
||||
exit 1
|
||||
|
|
|
@ -17,7 +17,9 @@ RUN set -ex; \
|
|||
chown -R postgres:postgres "$PGDATA"
|
||||
|
||||
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; \
|
||||
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
|
||||
fi
|
||||
|
||||
# # Delete the datadir once (needed for the migration from debian to alpine)
|
||||
# if ! [ -f "$DUMP_DIR/initial-cleanup-done" ]; then
|
||||
# rm -rf "${DATADIR:?}/"*
|
||||
# touch "$DUMP_DIR/initial-cleanup-done"
|
||||
# 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
|
||||
rm -rf "${DATADIR:?}/"*
|
||||
touch "$DUMP_DIR/initial-cleanup-done"
|
||||
set +ex
|
||||
fi
|
||||
|
||||
# Test if some things match
|
||||
# shellcheck disable=SC2235
|
||||
|
|
Loading…
Reference in a new issue