Skip to content

Run Apache2 in background #215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: v3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions Dockerfile.slim.apache
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions utils/Dockerfile.slim.blueprint
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
23 changes: 22 additions & 1 deletion utils/apache2-foreground → utils/apache2-background
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion utils/docker-entrypoint-as-root.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down