2

Is there a way to check varnish configuration syntax without actually using the new version?

I'm searching for a native varnish equivalent of apache2ctl configtest

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
greg0ire
  • 2,925
  • 3
  • 25
  • 37

2 Answers2

4

You can ask Varnish to compile your VLC file to a temporary file. This is part of our script that loads a new configuration into our varnish servers:

tmpfile=$(mktemp)
trap 'rm -f $tmpfile' 0
varnishd -C -f /srv/web/fe/varnish/default.vcl > $tmpfile
echo

if [ ! -s $tmpfile ]; then
    echo "ERROR: There are errors in the varnish configuration." >&2
    exit 1
fi

This works because varnishd -C will not generate any output on stdout if there are errors in the VCL.

larsks
  • 32,449
  • 5
  • 54
  • 70
1

What's about varnish_reload_vcl?

Some examples:

  1. Without problems in your VCL file

    $ varnish_reload_vcl
    Loading vcl from /etc/varnish/default.vcl
    Current running config name is reload_2016-01-28T15:18:23
    Using new config name reload_2016-01-28T15:19:57
    VCL compiled.
    VCL 'reload_2016-01-28T15:19:57' now active
    available       0 boot
    available       0 reload_2016-01-28T14:40:04
    available       0 reload_2016-01-28T14:42:07
    available       0 reload_2016-01-28T14:42:32
    available       0 reload_2016-01-28T14:47:45
    available       0 reload_2016-01-28T14:48:45
    available       0 reload_2016-01-28T14:50:26
    available       0 reload_2016-01-28T14:55:55
    available       0 reload_2016-01-28T15:18:23
    active          0 reload_2016-01-28T15:19:57
    
    Done
    
  2. With an error in your VCL file

    $ varnish_reload_vcl
    Loading vcl from /etc/varnish/default.vcl
    Current running config name is reload_2016-01-28T15:19:57
    Using new config name reload_2016-01-28T15:21:51
    Message from VCC-compiler:
    Symbol not found: 'b1' (expected type BACKEND):
    ('input' Line 77 Pos 32)
            set req.backend_hint = b1;
    -------------------------------##-
    
    Running VCC-compiler failed, exited with 2
    VCL compilation failed
    Command failed with error code 106
    varnishadm -S /etc/varnish/secret -T 127.0.0.1:6082 vcl.load failed
    
A.B.
  • 3,372
  • 2
  • 17
  • 27