Bash profile function to reload Varnish config on the fly

Let's say we modifed a vcl (default.vcl in this case) and want to load into a running Varnish instance without something crazy like restarting it. Here's a little function I put in my .bashrc (seems too small to be a script) 🙂

# varnish vcl load
vload() {
        local conf="/etc/varnish/default.vcl"
        local f=$(date +%Y%m%d%H%M%S)
        local c="sudo varnishadm -T -S /etc/varnish/secret"
        $c vcl.load $f $conf && $c vcl.use $f && $c vcl.list

Because it's using "&&" between vcl.load and vcl.use, in case of error, vcl.use won't run so it should be safe.

On failure:

$ vload
Message from VCC-compiler:
Syntax error at
(input Line 130 Pos 14)
invalid junk \.
Running VCC-compiler failed, exit 1VCL compilation failed
Command failed with error code 106

On success:

$ vload 
VCL compiled.

available       0 boot
available       0 20101210030819
available       7 20101210032022
active          0 20101210040123

Leave a comment

NOTE: Enclose quotes in <blockquote></blockquote>. Enclose code in <pre lang="LANG"></pre> (where LANG is one of these).