diff --git a/Dockerfile.slim.apache b/Dockerfile.slim.apache index 597488d6..0a269609 100644 --- a/Dockerfile.slim.apache +++ b/Dockerfile.slim.apache @@ -194,10 +194,7 @@ RUN a2enconf docker-php ENV PHP_EXTRA_BUILD_DEPS apache2-dev ENV PHP_EXTRA_CONFIGURE_ARGS --with-apxs2 --disable-cgi -# https://httpd.apache.org/docs/2.4/stopping.html#gracefulstop -STOPSIGNAL SIGWINCH - -COPY utils/apache2-foreground /usr/local/bin/ +COPY utils/apache2-background /usr/local/bin/ EXPOSE 80 @@ -311,7 +308,7 @@ ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] RUN echo "ServerName localhost" > /etc/apache2/conf-available/servername.conf RUN a2enconf servername -CMD ["apache2-foreground"] +CMD ["apache2-background"] # |-------------------------------------------------------------------------- # | Entrypoint diff --git a/utils/Dockerfile.slim.blueprint b/utils/Dockerfile.slim.blueprint index 3d43ca25..0211c308 100644 --- a/utils/Dockerfile.slim.blueprint +++ b/utils/Dockerfile.slim.blueprint @@ -196,10 +196,7 @@ RUN a2enconf docker-php ENV PHP_EXTRA_BUILD_DEPS apache2-dev ENV PHP_EXTRA_CONFIGURE_ARGS --with-apxs2 --disable-cgi -# https://httpd.apache.org/docs/2.4/stopping.html#gracefulstop -STOPSIGNAL SIGWINCH - -COPY utils/apache2-foreground /usr/local/bin/ +COPY utils/apache2-background /usr/local/bin/ EXPOSE 80 @@ -329,7 +326,7 @@ ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] RUN echo "ServerName localhost" > /etc/apache2/conf-available/servername.conf RUN a2enconf servername -CMD ["apache2-foreground"] +CMD ["apache2-background"] # |-------------------------------------------------------------------------- # | Entrypoint diff --git a/utils/apache2-foreground b/utils/apache2-background similarity index 77% rename from utils/apache2-foreground rename to utils/apache2-background index 5fe22e26..901690cc 100755 --- a/utils/apache2-foreground +++ b/utils/apache2-background @@ -37,4 +37,25 @@ for e in "${!APACHE_@}"; do fi done -exec apache2 -DFOREGROUND "$@" +_shutdown() { + echo "Stopping Apache2 gracefully..." + + pid=$(cat "/var/run/apache2/apache2.pid") + apachectl graceful-stop + + echo "Waiting for PID $pid to exit..." + tail --pid=$pid -f /dev/null + + echo "Exiting..." + stop=true +} + +stop=false +trap _shutdown SIGTERM + +echo "Starting Apache2 in the background..." +apache2 -k start "$@" + +while [ "$stop" = false ]; do + sleep 0.5; +done diff --git a/utils/docker-entrypoint-as-root.sh b/utils/docker-entrypoint-as-root.sh index f8c6c9ea..0a5ad751 100755 --- a/utils/docker-entrypoint-as-root.sh +++ b/utils/docker-entrypoint-as-root.sh @@ -145,7 +145,7 @@ else fi # We should run the command with the user of the directory... (unless this is Apache, that must run as root...) -if [[ "$@" == "apache2-foreground" ]]; then +if [[ "$@" == "apache2-background" ]]; then /usr/local/bin/apache-expose-envvars.sh; exec "$@"; else