rotating the varnishncsa log file

Raymond Hall kova70 at gmail.com
Tue Sep 23 19:12:43 CEST 2008


Hi Chris,

It all depends on you init scripts setup.
On a red hat based system (centos, rhel, fedora, mandrake, suse,
etc.), I just hacked the standard varnishlog init
(/etc/init.d/varnishlog) from the rpm, the relevant changes are these:

DAEMON="/usr/bin/varnishncsa-hack"
PIDFILE="/var/run/varnish/varnishlog.pid"
LOCKFILE="/var/lock/subsys/varnishlog"
LOGFILE="/var/log/varnish/varnish.log"
DAEMON_OPTS="-c -a -w ${LOGFILE} -D -P $PIDFILE"

So when logrotate does: /bin/kill -HUP `cat
/var/run/varnish/varnishlog.pid 2>/dev/null` 2> /dev/null || true
It actually resets varnishncsa logging.  I guess it'd be nicer to
write a proper varnishncsa init.d and logrotate scripts. Its easy
based on the original varnishlog scripts.

It seems that you're using debian. Did you write an init/d script for
varnishncsa or are you starting it elsewhere? If you wrote an init.d
script, then that's the one you want in the invoke-rc.d line. If you
didn't, that you have to notice where are you saving the pid the
process so you can do a kill -HUP on it. (which is what the init.d
script with reload arg does)

regards,
Ray

On Mon, Sep 22, 2008 at 6:44 PM, Chris Johnson <cjohnson at socialvibe.com> wrote:
> Thank you for your replies Raymond and Nathan.
> Can you possibly shed some light on the " /usr/sbin/invoke-rc.d" part?  Read
> on for more context...
>
> I want to use logrotate to rotate the varnish log files.  I found the file
> (/home/username/varnish-1.1.1/debian/varnish.logrotate) containing the
> following:
>>>>
> /var/log/varnish/varnish.log {
>  daily
>  rotate 7
>  compress
>  delaycompress
>  postrotate
>    /usr/sbin/invoke-rc.d varnishlog reload > /dev/null
>  endscript
> }
>>>>
>
> However, we are using varnishncsa and not varnishlog. Running "ps aux | grep
> varnish" yields:
>>>
> /opt/varnish/sbin/varnishd
> /opt/varnish/bin/varnishncsa -a -c -w /var/log/varnish.log
>>>
>
> Is setting up logrotate for varnishncsa as simple as changing the
> invoke-rc.d line of the logrotate file to be:
>>>
>    /usr/sbin/invoke-rc.d varnishncsa reload > /dev/null
>>>
>
> If so, how to pass in the ncsa commandline parameters?
>
> Thanks for any guidance.
> -Chris
>
> On Sep 5, 2008, at 10:39 AM, Nathan Kinkade wrote:
>
> 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
> }
> ===========================
>
>
> _______________________________________________
> varnish-misc mailing list
> varnish-misc at projects.linpro.no
> http://projects.linpro.no/mailman/listinfo/varnish-misc
>
>



-- 
I'd rather have an inch of a dog than miles of pedigree.

Dana Burnet



More information about the varnish-misc mailing list