有没有办法在不实际使用新版本的情况下检查清漆配置语法?
我正在寻找相当于本机清漆apache2ctl configtest
答案1
您可以要求 Varnish 将您的 VLC 文件编译为临时文件。这是我们脚本的一部分,它将新配置加载到我们的清漆服务器中:
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
这是可行的,因为如果 VCL 中存在错误,varnishd -C
则不会生成任何输出。stdout
答案2
是关于什么的varnish_reload_vcl
?
一些例子:
VCL 文件没有问题
$ 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
VCL 文件中有错误
$ 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