From 1f1032bf96fdc966aa3f31bef72b6df13f972fbc Mon Sep 17 00:00:00 2001 From: Clarence Ho Date: Mon, 18 Jan 2021 15:09:20 -0800 Subject: [PATCH] Fix log file issues - when running in docker, php-fpm child proceses can't write to log files which are symbolic linked to /dev/stderr. seems to be related to permissions and how cake/php uses fopen when writing to pipes. - this fix create pipes before starting the php-fpm master process. these pipes are redirected to stderr --- Dockerfile | 7 +++---- docker/docker-entrypoint-php-fpm.sh | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) create mode 100755 docker/docker-entrypoint-php-fpm.sh diff --git a/Dockerfile b/Dockerfile index 4d0761ccf..f15f14efe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,15 +18,13 @@ RUN apt-get update && apt-get install --no-install-recommends --no-install-sugge COPY docker/php.ini /usr/local/etc/php/ COPY . /var/www/html +COPY docker/docker-entrypoint-php-fpm.sh / RUN cd /var/www/html \ && composer install --no-ansi --no-dev --no-interaction --no-plugins --no-progress --no-suggest --optimize-autoloader \ && mkdir -p /var/www/html/app/tmp/cache/persistent /var/www/html/app/tmp/cache/models /var/www/html/app/tmp/logs \ && chown www-data:www-data -R /var/www/html/app/tmp/cache \ - && ln -sf /dev/stdout /var/www/html/app/tmp/logs/api.log \ - && ln -sf /dev/stdout /var/www/html/app/tmp/logs/debug.log \ - && ln -sf /dev/stdout /var/www/html/app/tmp/logs/login.log \ - && ln -sf /dev/stderr /var/www/html/app/tmp/logs/error.log + && chown www-data:www-data -R /var/www/html/app/tmp/logs RUN set -ex \ ## Customize PHP fpm configuration @@ -34,3 +32,4 @@ RUN set -ex \ && sed -i -e "s/;request_terminate_timeout\s*=[^\n]*/request_terminate_timeout = 300/g" /usr/local/etc/php-fpm.conf \ && php-fpm --test +CMD ["/docker-entrypoint-php-fpm.sh"] \ No newline at end of file diff --git a/docker/docker-entrypoint-php-fpm.sh b/docker/docker-entrypoint-php-fpm.sh new file mode 100755 index 000000000..f9653368e --- /dev/null +++ b/docker/docker-entrypoint-php-fpm.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +# hacks to allow php-fpm child process to write to log files that redirected to stderr +# similar to https://github.com/moby/moby/issues/6880#issuecomment-344114520 +chown www-data:www-data /var/www/html/app/tmp/logs +for f in /var/www/html/app/tmp/logs/api.log \ + /var/www/html/app/tmp/logs/debug.log \ + /var/www/html/app/tmp/logs/error.log \ + /var/www/html/app/tmp/logs/login.log +do + rm -f $f + mkfifo -m 600 $f + chown www-data:www-data $f + cat <> $f 1>&2 & +done + +php-fpm