Add docker examples for restore services up
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
#!/bin/bash
|
||||
# Custom entrypoint for Nextcloud Docker container
|
||||
# Handles restore initialization, permission fixes, and maintenance mode
|
||||
|
||||
set -e
|
||||
|
||||
# Fix permissions on mounted volumes
|
||||
if [ -d "/var/www/html/data" ]; then
|
||||
chown -R www-data:www-data /var/www/html/data 2>/dev/null || true
|
||||
find /var/www/html/data -type d -exec chmod 750 {} \; 2>/dev/null || true
|
||||
find /var/www/html/data -type f -exec chmod 640 {} \; 2>/dev/null || true
|
||||
fi
|
||||
|
||||
if [ -d "/var/www/html/config" ]; then
|
||||
chown -R www-data:www-data /var/www/html/config 2>/dev/null || true
|
||||
find /var/www/html/config -type f -exec chmod 640 {} \; 2>/dev/null || true
|
||||
fi
|
||||
|
||||
if [ -d "/var/www/html/custom_apps" ]; then
|
||||
chown -R www-data:www-data /var/www/html/custom_apps 2>/dev/null || true
|
||||
find /var/www/html/custom_apps -type d -exec chmod 750 {} \; 2>/dev/null || true
|
||||
find /var/www/html/custom_apps -type f -exec chmod 640 {} \; 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# If config exists, wait for database and run post-restore steps
|
||||
if [ -f "/var/www/html/config/config.php" ]; then
|
||||
echo "Config found, checking database connection..."
|
||||
|
||||
# Extract DB config
|
||||
if grep -q "'dbtype' => 'pgsql'" /var/www/html/config/config.php; then
|
||||
DB_TYPE="pgsql"
|
||||
DB_HOST=$(grep -oP "'dbhost'\s*=>\s*'\K[^']+" /var/www/html/config/config.php 2>/dev/null || echo "db")
|
||||
DB_PORT=$(grep -oP "'dbport'\s*=>\s*\K[0-9]+" /var/www/html/config/config.php 2>/dev/null || echo "5432")
|
||||
else
|
||||
DB_TYPE="mysql"
|
||||
DB_HOST=$(grep -oP "'dbhost'\s*=>\s*'\K[^']+" /var/www/html/config/config.php 2>/dev/null || echo "db")
|
||||
DB_PORT=$(grep -oP "'dbport'\s*=>\s*\K[0-9]+" /var/www/html/config/config.php 2>/dev/null || echo "3306")
|
||||
fi
|
||||
DB_USER=$(grep -oP "'dbuser'\s*=>\s*'\K[^']+" /var/www/html/config/config.php 2>/dev/null || echo "nextcloud")
|
||||
DB_PASS=$(grep -oP "'dbpassword'\s*=>\s*'\K[^']+" /var/www/html/config/config.php 2>/dev/null || echo "")
|
||||
DB_NAME=$(grep -oP "'dbname'\s*=>\s*'\K[^']+" /var/www/html/config/config.php 2>/dev/null || echo "nextcloud")
|
||||
|
||||
# Wait for database
|
||||
for i in {1..60}; do
|
||||
if [ "$DB_TYPE" = "pgsql" ]; then
|
||||
if PGPASSWORD="$DB_PASS" pg_isready -h "$DB_HOST" -p "$DB_PORT" -U "$DB_USER" -d "$DB_NAME" >/dev/null 2>&1; then
|
||||
echo "PostgreSQL connection successful"
|
||||
break
|
||||
fi
|
||||
else
|
||||
if mariadb -h "$DB_HOST" -P "$DB_PORT" -u "$DB_USER" -p"$DB_PASS" -e "SELECT 1" "$DB_NAME" >/dev/null 2>&1; then
|
||||
echo "MariaDB/MySQL connection successful"
|
||||
break
|
||||
fi
|
||||
fi
|
||||
echo "Waiting for database... ($i/60)"
|
||||
sleep 2
|
||||
done
|
||||
|
||||
# Disable maintenance mode if enabled
|
||||
echo "Disabling maintenance mode..."
|
||||
sudo -u www-data php /var/www/html/occ maintenance:mode --off 2>/dev/null || true
|
||||
|
||||
# Run upgrade if needed
|
||||
echo "Running Nextcloud upgrade..."
|
||||
sudo -u www-data php /var/www/html/occ upgrade 2>/dev/null || true
|
||||
|
||||
# Fix database
|
||||
echo "Fixing database schema..."
|
||||
sudo -u www-data php /var/www/html/occ db:add-missing-indices 2>/dev/null || true
|
||||
sudo -u www-data php /var/www/html/occ db:add-missing-primary-keys 2>/dev/null || true
|
||||
sudo -u www-data php /var/www/html/occ db:convert-filecache-bigint --no-interaction 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Execute original entrypoint
|
||||
exec /usr/local/bin/docker-entrypoint.sh "$@"
|
||||
Reference in New Issue
Block a user