rotating the varnishncsa log file

Nathan Kinkade nkinkade at creativecommons.org
Fri Sep 5 19:39:23 CEST 2008


2008/9/4 Chris Johnson <cjohnson at socialvibe.com>:
> Does anyone successfully have logrotate working with varnishncsa?
>
> Thanks,
> Chrs

Below is the solution I came up with.  The lastaction part may not be
necessary for anyone else, but on occasion it seemed to be necessary
for us, and rather than spending much time looking into the underlying
cause I'm okay with this solution.

Nathan

/etc/logrotate.d/varnish
===========================
/var/log/varnish/varnish.log {
  daily
  rotate 52
  compress
  create
  delaycompress
  dateext
  postrotate
    /usr/sbin/invoke-rc.d varnishlog reload > /dev/null
    DATE=$(date +%Y%m%d)
    VDIR=/var/log/varnish
    # varnishlog or varnishncsa(??) seems to produce a lot of entries
that are null,
    # the grep -v in the middle just attempts to eliminate them
    /usr/bin/ionice -c3 /usr/bin/varnishncsa -r
$VDIR/varnish.log-$DATE | grep -v '^- - -' | gzip >
$VDIR/varnish.log-$DATE.gz && rm $VDIR/varnish.log-
$DATE
  endscript
  lastaction
    # Sometimes, for reasons that I can't explain, varnishlog stops
logging after
    # rotation.  The new log just sits there at 0 bytes and it takes a reload to
    # make it start logging again.  It could be some complex timing issue, but
    # hopefully just adding one last restart of varnishlog will be enough.
    /usr/sbin/invoke-rc.d varnishlog force-reload > /dev/null
  endscript
}
===========================



More information about the varnish-misc mailing list