From bdde0ee03a52f760502702eedb70260a371fd068 Mon Sep 17 00:00:00 2001 From: dpedu Date: Sat, 5 Sep 2015 22:44:14 -0700 Subject: [PATCH] Add syslog logging for varnish --- Dockerfile | 3 +++ README.md | 2 ++ monitorvcl | 6 ++++++ rsyslogd.conf | 2 ++ start | 11 ++++++++++- varnishlog.conf | 2 ++ varnishlogger.conf | 5 +++++ 7 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 monitorvcl create mode 100644 rsyslogd.conf create mode 100644 varnishlog.conf create mode 100644 varnishlogger.conf diff --git a/Dockerfile b/Dockerfile index 748564b..7465557 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,6 +13,9 @@ RUN chmod +x /start ;\ rm /etc/varnish/secret ADD varnish.conf /etc/supervisor/conf.d/varnish.conf +ADD varnishlogger.conf /etc/supervisor/conf.d/varnishlogger.conf +ADD varnishlog.conf /etc/rsyslog.d/varnishlog.conf +ADD rsyslogd.conf /etc/supervisor/conf.d/rsyslogd.conf ADD supervisor.conf /etc/supervisor/conf.d/supervisor.conf WORKDIR /etc/varnish diff --git a/README.md b/README.md index 08b7f3f..56e8f5a 100644 --- a/README.md +++ b/README.md @@ -17,3 +17,5 @@ Container for running [Varnish Cache](https://www.varnish-cache.org/). Automatic *Extras* * test.vcl - example default.vcl file +* monitorvcl - example showing how reload varnish when the vcl is modified +* Apache-format logs are sent to the docker host with rsyslog with programname 'varnish', channel local6.notice diff --git a/monitorvcl b/monitorvcl new file mode 100644 index 0000000..48b89d3 --- /dev/null +++ b/monitorvcl @@ -0,0 +1,6 @@ +#!/bin/bash + +# Wait for the vcl to be modified then tell varnish to reload +while inotifywait -qq --event modify /etc/varnish/default.vcl; do + pkill -HUP varnishd +done \ No newline at end of file diff --git a/rsyslogd.conf b/rsyslogd.conf new file mode 100644 index 0000000..365f69f --- /dev/null +++ b/rsyslogd.conf @@ -0,0 +1,2 @@ +[program:rsyslog] +command=rsyslogd -n diff --git a/start b/start index 2bf2577..c55d402 100644 --- a/start +++ b/start @@ -3,18 +3,27 @@ # Cleanly kill supervisor when container is stopped trap 'kill $(jobs -p)' EXIT +# Set default varnish memory cache size if not specified if [ -z "$MEMSIZE" ]; then export MEMSIZE=64M fi +# Set varnish secret if not specified if [ ! -f /etc/varnish/secret ]; then if [ -z "$SECRET" ]; then SECRET=`cat /proc/sys/kernel/random/uuid` fi echo $SECRET > /etc/varnish/secret fi +echo "Secret is $SECRET" -echo "Secret is `cat /etc/varnish/secret`" +# Set access syslog host if not specified +if [ -z "$LOGHOST" ]; then + LOGHOST=`ip route | grep default | awk '{print $3}'` +fi +sed -i -E "s/@.+/@$LOGHOST/" /etc/rsyslog.d/varnishlog.conf + +# Check vcl syntax varnishd -C -f /etc/varnish/default.vcl > /dev/null || exit 1 supervisord diff --git a/varnishlog.conf b/varnishlog.conf new file mode 100644 index 0000000..0af24f0 --- /dev/null +++ b/varnishlog.conf @@ -0,0 +1,2 @@ +if $programname == 'varnish' then @172.17.42.1 +& ~ \ No newline at end of file diff --git a/varnishlogger.conf b/varnishlogger.conf new file mode 100644 index 0000000..fc2b7fe --- /dev/null +++ b/varnishlogger.conf @@ -0,0 +1,5 @@ +[program:varnishlogger] +command=bash -c "varnishncsa -F '%%{X-Real-IP}i %%l %%u %%t \"%%r\" %%s %%b \"%%{Referer}i\" \"%%{User-agent}i\"' | /usr/bin/logger -tvarnish -plocal6.notice" +autostart=true +autorestart=true +redirect_stderr=true