Răsfoiți Sursa

Railway image: set Apache's port the same way on every start (#5901)

The entrypoint rewrote "Listen 80" and ":80" with unanchored patterns. When a
container started again with its filesystem kept (docker restart, possibly
Railway's ON_FAILURE retries), "Listen 8080" matched again and became
"Listen 808080", Apache failed with AH00526 and the container could not come
back. Both substitutions now match the whole Listen and VirtualHost lines with
any port, so every start writes the same lines.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Andrey Yasko 4 zile în urmă
părinte
comite
84eced713e
1 a modificat fișierele cu 5 adăugiri și 4 ștergeri
  1. 5 4
      scripts/railway/entrypoint.sh

+ 5 - 4
scripts/railway/entrypoint.sh

@@ -4,10 +4,11 @@ set -eu
 cd /var/www/html
 
 PORT="${PORT:-80}"
-if [ "$PORT" != "80" ]; then
-    sed -i "s/Listen 80/Listen ${PORT}/" /etc/apache2/ports.conf
-    sed -i "s/:80/:${PORT}/g" /etc/apache2/sites-available/000-default.conf
-fi
+# Whole-line patterns that take any port, not only the image's 80: a restart that keeps the
+# container's filesystem (docker restart, Railway's ON_FAILURE retries) finds the port an
+# earlier start wrote and sets it again, where a bare "Listen 80" would turn 8080 into 808080.
+sed -i "s/^Listen [0-9][0-9]*$/Listen ${PORT}/" /etc/apache2/ports.conf
+sed -i "s/^<VirtualHost \*:[0-9][0-9]*>$/<VirtualHost *:${PORT}>/" /etc/apache2/sites-available/000-default.conf
 a2dismod mpm_event mpm_worker >/dev/null 2>&1 || true
 a2enmod mpm_prefork rewrite >/dev/null 2>&1 || true