From 422cb5c8ab9bba2d6be9d8d62936aa78ea79f3bb Mon Sep 17 00:00:00 2001 From: Tero Date: Sat, 24 Oct 2026 14:02:30 +0300 Subject: [PATCH] Entrypoint fixes --- ep-piwigo-docker/Dockerfile | 11 +++---- ep-piwigo-docker/docker-startup.sh | 47 ++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 ep-piwigo-docker/docker-startup.sh diff --git a/ep-piwigo-docker/Dockerfile b/ep-piwigo-docker/Dockerfile index 6ffbce4..27a0ba2 100644 --- a/ep-piwigo-docker/Dockerfile +++ b/ep-piwigo-docker/Dockerfile @@ -16,9 +16,10 @@ RUN mkdir -p /usr/local/etc/php/conf.d && \ echo 'post_max_size = 100M' >> /usr/local/etc/php/conf.d/piwigo-custom.ini && \ echo 'max_file_uploads = 50' >> /usr/local/etc/php/conf.d/piwigo-custom.ini -# Copy custom entrypoint for restore support -COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh -RUN chmod +x /usr/local/bin/docker-entrypoint.sh +# Copy custom startup script (runs before main entrypoint) +COPY docker-startup.sh /usr/local/bin/docker-startup.sh +RUN chmod +x /usr/local/bin/docker-startup.sh -ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] -CMD ["apache2-foreground"] \ No newline at end of file +# Run startup script before main entrypoint +# Use base image's entrypoint (docker-php-entrypoint) +CMD ["/usr/local/bin/docker-startup.sh"] \ No newline at end of file diff --git a/ep-piwigo-docker/docker-startup.sh b/ep-piwigo-docker/docker-startup.sh new file mode 100644 index 0000000..d04b8a8 --- /dev/null +++ b/ep-piwigo-docker/docker-startup.sh @@ -0,0 +1,47 @@ +#!/bin/bash +# Custom startup script for Piwigo Docker container +# Runs before the main entrypoint (docker-php-entrypoint) + +set -e + +# Fix permissions on mounted volumes +if [ -d "/var/www/html/upload" ]; then + chown -R www-data:www-data /var/www/html/upload 2>/dev/null || true + find /var/www/html/upload -type d -exec chmod 755 {} \; 2>/dev/null || true + find /var/www/html/upload -type f -exec chmod 644 {} \; 2>/dev/null || true +fi + +if [ -d "/var/www/html/local/config" ]; then + chown -R www-data:www-data /var/www/html/local/config 2>/dev/null || true + find /var/www/html/local/config -type f -exec chmod 644 {} \; 2>/dev/null || true +fi + +if [ -d "/var/www/html/galleries" ]; then + chown -R www-data:www-data /var/www/html/galleries 2>/dev/null || true + find /var/www/html/galleries -type d -exec chmod 755 {} \; 2>/dev/null || true + find /var/www/html/galleries -type f -exec chmod 644 {} \; 2>/dev/null || true +fi + +# If config exists but no database, wait for DB +if [ -f "/var/www/html/local/config/config.inc.php" ]; then + echo "Config found, checking database connection..." + + # Extract DB config from config.inc.php + DB_HOST=$(grep -oP "'db_host'\s*=>\s*'\K[^']+" /var/www/html/local/config/config.inc.php 2>/dev/null || echo "db") + DB_USER=$(grep -oP "'db_user'\s*=>\s*'\K[^']+" /var/www/html/local/config/config.inc.php 2>/dev/null || echo "piwigo") + DB_PASS=$(grep -oP "'db_password'\s*=>\s*'\K[^']+" /var/www/html/local/config/config.inc.php 2>/dev/null || echo "") + DB_NAME=$(grep -oP "'db_name'\s*=>\s*'\K[^']+" /var/www/html/local/config/config.inc.php 2>/dev/null || echo "piwigo") + + # Wait for database + for i in {1..30}; do + if mariadb -h "$DB_HOST" -u "$DB_USER" -p"$DB_PASS" -e "SELECT 1" "$DB_NAME" >/dev/null 2>&1; then + echo "Database connection successful" + break + fi + echo "Waiting for database... ($i/30)" + sleep 2 + done +fi + +# Execute original Piwigo entrypoint +exec docker-php-entrypoint "$@" \ No newline at end of file