From 9e992f60819c2b07e40a6e0a5fc74e6334487745 Mon Sep 17 00:00:00 2001
From: Manuel Herrmann <0@0x17.de>
Date: Sun, 11 Jun 2017 18:42:59 +0200
Subject: [PATCH] added sysklogd as syslogger; redirected nginx messages;
 startup script improvements

---
 docker/DockerfileNginx |  1 +
 docker/run-web.sh      | 27 ++++++++++++++++++++++++---
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/docker/DockerfileNginx b/docker/DockerfileNginx
index 926512e..724e573 100644
--- a/docker/DockerfileNginx
+++ b/docker/DockerfileNginx
@@ -1,5 +1,6 @@
 FROM richarvey/nginx-php-fpm
 
+RUN apk add --no-cache sysklogd
 ADD run-web.sh /
 RUN chmod 755 /run-web.sh
 
diff --git a/docker/run-web.sh b/docker/run-web.sh
index d6c2d4d..74bf5b6 100755
--- a/docker/run-web.sh
+++ b/docker/run-web.sh
@@ -1,18 +1,22 @@
 #!/bin/bash
 
+# fix php-fpm
 sed -ri '
 /^php_flag\[display_errors\]/ d
-$ a php_flag[display_errors] = on
 ' /usr/local/etc/php-fpm.conf
 
-sed -ri '
+# check if our changes were applied yet
+if ! grep -E '^\[program:sysklogd\]$' /etc/supervisord.conf >&/dev/null; then
+    # fix php-fpm configs
+    sed -ri '
 /^;?error_log/ c error_log = syslog
 /^;?syslog.facility/ c syslog.facility = daemon
 /^;?syslog.ident/ c syslog.ident = php-fpm
 /^;?log_level/ c log_level = notice
 ' /usr/local/etc/php-fpm.d/*.conf
 
-tee /usr/local/etc/php/conf.d/zzz-registration-system.ini << END
+    # add our own logging configuration
+    tee /usr/local/etc/php/conf.d/zzz-registration-system.ini >&/dev/null << END
 [PHP]
 error_reporting = E_ALL & ~E_NOTICE
 display_errors = On
@@ -24,4 +28,21 @@ track_errors = On
 html_errors = On
 END
 
+    # fix nginx config access_log/error_log targets
+    sed -ri \
+    's/^([ \t]*)((access|error)_log) .*$/\1\2 syslog:server=unix:\/dev\/log,facility=local7,tag=nginx;/' \
+    /etc/nginx/sites-enabled/* /etc/nginx/nginx.conf
+
+    # cleanup logging options in supervisord (startup)
+    sed -ri '/^std(err|out)_.*=/ d' /etc/supervisord.conf
+    # add syslogger entry at the end of supervisord config
+    tee -a /etc/supervisord.conf >&/dev/null <<END
+[program:sysklogd]
+command = /usr/sbin/syslogd -d
+autostart=true
+autorestart=true
+priority=1
+END
+fi
+
 exec /start.sh
-- 
GitLab