#!/bin/bash . /etc/init.d/functions retval=0 prog=varnishlog pidfile=/var/run/xvarnish/varnishlog.pid binlog=/var/log/xvarnish/errorvsl.bin # The VSL query, we only record requests matching the below conditions: # Any of: # - Any requests with these tag(s) present: Error, FetchError, VCL_Error, ESI_xmlerror # - Any requests with 503 status in reponse to client # - Ignore requests where the frontend's client aborted\lost their TCP connection VSLQ="(VCL_Error,Error,VSL,FetchError,ESI_xmlerror or RespStatus == 503) and not {1-}Debug ~ 'Connection reset by peer'" DAEMON_OPTS="-D -P $pidfile -t off -g request -q \"$VSLQ\" -a -w $binlog" check_status() { status -p $pidfile $prog >/dev/null 2>&1 } start() { check_status && stop echo -n "Starting $prog: " ulimit -u 2048 ulimit -u 10240 ulimit -u unlimited ulimit -n 131072 daemon --user varnish --pidfile $pidfile $prog $DAEMON_OPTS retval=$? echo return $retval } stop() { check_status || return 0 echo -n "Stopping $prog: " killproc -p $pidfile $prog retval=$? echo return $retval } # Start daemonized varnishlog start # Configure logrotate for weekly log rotation cat <<- EOF > /etc/logrotate.d/xvarnish-errorvsl $binlog { notifempty dateext rotate 5 missingok create 0600 varnish varnish postrotate /bin/kill -HUP \`cat $pidfile 2>/dev/null\` 2> /dev/null || true endscript } EOF