The printf approach writes the file inline in the RUN command, avoiding COPY/heredoc issues. It should now create /etc/cont-init.d/99-custom-startup correctly for s6-overlay to find.

This commit is contained in:
2026-10-24 14:15:07 +03:00
parent 80571b73b5
commit 512bc22685
+46 -47
View File
@@ -18,50 +18,49 @@ RUN mkdir -p /usr/local/etc/php/conf.d && \
# Create custom startup script in s6 init directory (runs during container init) # Create custom startup script in s6 init directory (runs during container init)
RUN mkdir -p /etc/cont-init.d && \ RUN mkdir -p /etc/cont-init.d && \
cat > /etc/cont-init.d/99-custom-startup << 'EOF' && \ printf '%s\n' '#!/bin/bash' \
chmod +x /etc/cont-init.d/99-custom-startup '# Custom startup script for Piwigo Docker container' \
#!/bin/bash '# Runs during s6-overlay init phase' \
# Custom startup script for Piwigo Docker container '' \
# Runs during s6-overlay init phase 'set -e' \
'' \
set -e '# Fix permissions on mounted volumes' \
'if [ -d "/var/www/html/upload" ]; then' \
# Fix permissions on mounted volumes ' chown -R www-data:www-data /var/www/html/upload 2>/dev/null || true' \
if [ -d "/var/www/html/upload" ]; then ' find /var/www/html/upload -type d -exec chmod 755 {} \; 2>/dev/null || true' \
chown -R www-data:www-data /var/www/html/upload 2>/dev/null || true ' find /var/www/html/upload -type f -exec chmod 644 {} \; 2>/dev/null || true' \
find /var/www/html/upload -type d -exec chmod 755 {} \; 2>/dev/null || true 'fi' \
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' \
if [ -d "/var/www/html/local/config" ]; then ' find /var/www/html/local/config -type f -exec chmod 644 {} \; 2>/dev/null || true' \
chown -R www-data:www-data /var/www/html/local/config 2>/dev/null || true 'fi' \
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' \
if [ -d "/var/www/html/galleries" ]; then ' find /var/www/html/galleries -type d -exec chmod 755 {} \; 2>/dev/null || true' \
chown -R www-data:www-data /var/www/html/galleries 2>/dev/null || true ' find /var/www/html/galleries -type f -exec chmod 644 {} \; 2>/dev/null || true' \
find /var/www/html/galleries -type d -exec chmod 755 {} \; 2>/dev/null || true 'fi' \
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' \
# If config exists but no database, wait for DB ' echo "Config found, checking database connection..."' \
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")' \
# Extract DB config from config.inc.php ' DB_USER=$(grep -oP '"'"'"'"'"'"'db_user'"'"'"'"'"'"'\s*=>\s*'"'"'"'"'"'"'\K[^'"'"'"'"'"'"']+'"'"'"'"'"'"' /var/www/html/local/config/config.inc.php 2>/dev/null || echo "piwigo")' \
DB_HOST=$(grep -oP "'db_host'\s*=>\s*'\K[^']+" /var/www/html/local/config/config.inc.php 2>/dev/null || echo "db") ' DB_PASS=$(grep -oP '"'"'"'"'"'"'db_password'"'"'"'"'"'"'\s*=>\s*'"'"'"'"'"'"'\K[^'"'"'"'"'"'"']+'"'"'"'"'"'"' /var/www/html/local/config/config.inc.php 2>/dev/null || echo "")' \
DB_USER=$(grep -oP "'db_user'\s*=>\s*'\K[^']+" /var/www/html/local/config/config.inc.php 2>/dev/null || echo "piwigo") ' DB_NAME=$(grep -oP '"'"'"'"'"'"'db_name'"'"'"'"'"'"'\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' \
# Wait for database ' if mariadb -h "$DB_HOST" -u "$DB_USER" -p"$DB_PASS" -e "SELECT 1" "$DB_NAME" >/dev/null 2>&1; then' \
for i in {1..30}; do ' echo "Database connection successful"' \
if mariadb -h "$DB_HOST" -u "$DB_USER" -p"$DB_PASS" -e "SELECT 1" "$DB_NAME" >/dev/null 2>&1; then ' break' \
echo "Database connection successful" ' fi' \
break ' echo "Waiting for database... ($i/30)"' \
fi ' sleep 2' \
echo "Waiting for database... ($i/30)" ' done' \
sleep 2 'fi' \
done > /etc/cont-init.d/99-custom-startup && \
fi chmod +x /etc/cont-init.d/99-custom-startup
EOF