Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
fix(assets): Ensure apache2/fpm running as PID 1 (#536)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lberruti authored Aug 29, 2023
1 parent 26afb39 commit 52b3c53
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ ENV GROUP_ID=

VOLUME [ "/opt/kimai/var" ]

ENTRYPOINT /startup.sh
CMD [ "/startup.sh" ]



Expand Down
3 changes: 1 addition & 2 deletions assets/service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -59,4 +59,3 @@ function runServer() {
waitForDB
handleStartup
runServer
exit
13 changes: 8 additions & 5 deletions assets/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -96,5 +100,4 @@ function handleStartup() {
config
handleStartup

/service.sh
exit
exec /service.sh

0 comments on commit 52b3c53

Please sign in to comment.