清漆配置測試

清漆配置測試

有沒有辦法在不實際使用新版本的情況下檢查清漆配置語法?

我正在尋找相當於本機清漆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

一些例子:

  1. 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
    
  2. 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
    

相關內容