From 52b3c532769e272e0bc3a337b6c6a3ce2f72076c Mon Sep 17 00:00:00 2001 From: lberruti Date: Tue, 29 Aug 2023 14:39:23 +0200 Subject: [PATCH] fix(assets): Ensure apache2/fpm running as PID 1 (#536) In order to stop container quickly, we need to run apache2 or fpm as PID 1 * Use CMD "exec form" instead of "shell form" * Use exec "binary" instead of "binary" * Use apache2 instead of apache2ctl * See also https://docs.docker.com/engine/reference/builder/#understand-how-cmd-and-entrypoint-interact --- Dockerfile | 2 +- assets/service.sh | 3 +-- assets/startup.sh | 13 ++++++++----- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 757d8ab..e6d2583 100644 --- a/Dockerfile +++ b/Dockerfile @@ -265,7 +265,7 @@ ENV GROUP_ID= VOLUME [ "/opt/kimai/var" ] -ENTRYPOINT /startup.sh +CMD [ "/startup.sh" ] diff --git a/assets/service.sh b/assets/service.sh index fa4fc8f..ac5d1b5 100755 --- a/assets/service.sh +++ b/assets/service.sh @@ -48,7 +48,7 @@ function runServer() { /opt/kimai/bin/console kimai:reload --env="$APP_ENV" chown -R $USER_ID:$GROUP_ID /opt/kimai/var if [ -e /use_apache ]; then - /usr/sbin/apache2ctl -D FOREGROUND + exec /usr/sbin/apache2 -D FOREGROUND elif [ -e /use_fpm ]; then exec php-fpm else @@ -59,4 +59,3 @@ function runServer() { waitForDB handleStartup runServer -exit diff --git a/assets/startup.sh b/assets/startup.sh index c26684c..8f6ac7d 100755 --- a/assets/startup.sh +++ b/assets/startup.sh @@ -80,10 +80,14 @@ function handleStartup() { fi if [ -e /use_apache ]; then - echo "APACHE_RUN_USER=$(id -nu "$USER_ID")" >> /etc/apache2/envvars + export APACHE_RUN_USER=$(id -nu "$USER_ID") # This doesn't _exactly_ run as the specified GID, it runs as the GID of the specified user but WTF - echo "APACHE_RUN_GROUP=$(id -ng "$USER_ID")" >> /etc/apache2/envvars - tail -n2 /etc/apache2/envvars + export APACHE_RUN_GROUP=$(id -ng "$USER_ID") + export APACHE_PID_FILE=/var/run/apache2/apache2.pid + export APACHE_RUN_DIR=/var/run/apache2 + export APACHE_LOCK_DIR=/var/lock/apache2 + export APACHE_LOG_DIR=/var/log/apache2 + export LANG=C elif [ -e /use_fpm ]; then sed -i "s/user = .*/user = $USER_ID/g" /usr/local/etc/php-fpm.d/www.conf sed -i "s/group = .*/group = $GROUP_ID/g" /usr/local/etc/php-fpm.d/www.conf @@ -96,5 +100,4 @@ function handleStartup() { config handleStartup -/service.sh -exit +exec /service.sh