From a8f5c7cea9c5a96de95c0747b9d15a545ac75ca6 Mon Sep 17 00:00:00 2001 From: Markus Blaschke Date: Fri, 16 Oct 2015 00:57:11 +0200 Subject: [PATCH] Implemented logfiles via named pipes Related #9 --- docker/main/bin/entrypoint.sh | 12 ++++++++++++ docker/main/bin/logwatch.sh | 16 +++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/docker/main/bin/entrypoint.sh b/docker/main/bin/entrypoint.sh index 4f7a0d6..9e6efed 100755 --- a/docker/main/bin/entrypoint.sh +++ b/docker/main/bin/entrypoint.sh @@ -10,6 +10,12 @@ else bash /opt/docker/bin/provision.sh entrypoint > /dev/null fi +function createNamedPipe() { + rm --force -- "$1" + mknod "$1" p +} + + ############################# ## COMMAND ############################# @@ -18,6 +24,12 @@ case "$1" in ## Supervisord (start daemons) supervisord) + + # Create named pipes for direct log output + createNamedPipe /tmp/php.slow.log + createNamedPipe /tmp/php.error.log + createNamedPipe /tmp/php.access.log + ## Register IP ETH0_IP=$(hostname -i) mkdir -p /data/dns/ diff --git a/docker/main/bin/logwatch.sh b/docker/main/bin/logwatch.sh index 729e0ca..2167f6d 100644 --- a/docker/main/bin/logwatch.sh +++ b/docker/main/bin/logwatch.sh @@ -1,8 +1,22 @@ #!/usr/bin/env bash +trap 'echo sigterm ; exit' SIGTERM +trap 'echo sigkill ; exit' SIGKILL + set -o pipefail # trace ERR through pipes set -o errtrace # trace ERR through 'time command' and other functions set -o nounset ## set -u : exit the script if you try to use an uninitialised variable set -o errexit ## set -e : exit the script if any statement returns a non-true return value -tail -F --quiet $2 | sed --unbuffered -e "s/^/\[$1\] /" +LOG_FACILITY="$1" +LOG_FILE="$2" + +# Create pipe +if [ -f "${LOG_FILE}" ]; then + mknod "${LOG_FILE}" p +fi + +# Output content +while true; do + sed --unbuffered -e "s/^/\[${LOG_FACILITY}\] /" < "${LOG_FILE}" +done