Skip to content

Commit

Permalink
Merge pull request #5441 from nextcloud/enh/noid/add-db-type
Browse files Browse the repository at this point in the history
nextcloud&notify-push: allow to adjust the DATABASE_TYPE
  • Loading branch information
szaimen authored Oct 24, 2024
2 parents 026b1b8 + 4be6d49 commit 680310c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
9 changes: 7 additions & 2 deletions Containers/nextcloud/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ run_upgrade_if_needed_due_to_app_update() {
fi
}

# Adjust DATABASE_TYPE to by Nextcloud supported value
if [ "$DATABASE_TYPE" = postgres ]; then
export DATABASE_TYPE=pgsql
fi

# Only start container if redis is accessible
# shellcheck disable=SC2153
while ! nc -z "$REDIS_HOST" "6379"; do
Expand Down Expand Up @@ -237,12 +242,12 @@ if ! [ -f "$NEXTCLOUD_DATA_DIR/skip.update" ]; then
);
DATADIR_PERMISSION_CONF

echo "Installing with PostgreSQL database"
echo "Installing with $DATABASE_TYPE database"
# Set a default value for POSTGRES_PORT
if [ -z "$POSTGRES_PORT" ]; then
POSTGRES_PORT=5432
fi
INSTALL_OPTIONS+=(--database pgsql --database-name "$POSTGRES_DB" --database-user "$POSTGRES_USER" --database-pass "$POSTGRES_PASSWORD" --database-host "$POSTGRES_HOST" --database-port "$POSTGRES_PORT")
INSTALL_OPTIONS+=(--database "$DATABASE_TYPE" --database-name "$POSTGRES_DB" --database-user "$POSTGRES_USER" --database-pass "$POSTGRES_PASSWORD" --database-host "$POSTGRES_HOST" --database-port "$POSTGRES_PORT")

echo "Starting Nextcloud installation..."
if ! php /var/www/html/occ maintenance:install "${INSTALL_OPTIONS[@]}"; then
Expand Down
5 changes: 5 additions & 0 deletions Containers/nextcloud/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ done
POSTGRES_USER="oc_$POSTGRES_USER"
export POSTGRES_USER

# Check that db type is not empty
if [ -z "$DATABASE_TYPE" ]; then
export DATABASE_TYPE=postgres
fi

# Fix false database connection on old instances
if [ -f "/var/www/html/config/config.php" ]; then
sleep 2
Expand Down
15 changes: 11 additions & 4 deletions Containers/notify-push/start.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/bin/bash

if [ -z "$NEXTCLOUD_HOST" ]; then
echo "NEXTCLOUD_HOST need to be provided. Exiting!"
echo "NEXTCLOUD_HOST needs to be provided. Exiting!"
exit 1
elif [ -z "$POSTGRES_HOST" ]; then
echo "POSTGRES_HOST need to be provided. Exiting!"
echo "POSTGRES_HOST needs to be provided. Exiting!"
exit 1
elif [ -z "$REDIS_HOST" ]; then
echo "REDIS_HOST need to be provided. Exiting!"
echo "REDIS_HOST needs to be provided. Exiting!"
exit 1
fi

Expand Down Expand Up @@ -52,9 +52,16 @@ fi
if [ -z "$REDIS_DB_INDEX" ]; then
REDIS_DB_INDEX=0
fi
# Set a default for db type
if [ -z "$DATABASE_TYPE" ]; then
DATABASE_TYPE=postgres
elif [ "$DATABASE_TYPE" != postgres ] && [ "$DATABASE_TYPE" != mysql ]; then
echo "DB type must be either postgres or mysql"
exit 1
fi

# Set sensitive values as env
export DATABASE_URL="postgres://oc_$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST:$POSTGRES_PORT/$POSTGRES_DB"
export DATABASE_URL="$DATABASE_TYPE://oc_$POSTGRES_USER:$POSTGRES_PASSWORD@$POSTGRES_HOST:$POSTGRES_PORT/$POSTGRES_DB"
export REDIS_URL="redis://:$REDIS_HOST_PASSWORD@$REDIS_HOST/$REDIS_DB_INDEX"

# Run it
Expand Down

0 comments on commit 680310c

Please sign in to comment.