When using Varnish Cache in an Alpine Linux 3.11 container, I suddenly found out that the reload functionality does not work.

$ /etc/init.d/varnishd reload
 * Reloading varnish ...
 * varnishd cannot load configuration

The system log had the following entries:

Jul 14 06:55:08 varnish local0.info varnishd[22976]: CLI telnet 127.0.0.1 52642 127.0.0.1 6082 Rd vcl.load reload_2020-07-14T06:55:08 /etc/varnish/default.vcl
Jul 14 06:55:08 varnish local0.info varnishd[22976]: CLI telnet 127.0.0.1 52642 127.0.0.1 6082 Wr 106 Illegal character in VCL name (':')
Jul 14 06:55:08 varnish daemon.err /etc/init.d/varnishd[23713]: varnishd cannot load configuration

Illegal character in VCL name error was confusing to me: I know I didn’t use any colons in file names nor procedure names. To find out what is wrong< I looked at the init script. reload() function was

reload() {
        checkconfig || return 1

        ebegin "Reloading varnish"

        $VARNISHADM vcl.list >/dev/null 2>&1
        ret=$?
        if [ $ret -ne 0 ]; then
                eerror "${SVCNAME} cannot list configuration"
                return 1
        fi

        new_config="reload_$(date +%FT%H:%M:%S)"
        $VARNISHADM vcl.load $new_config $CONFIGFILE >/dev/null 2>&1
        ret=$?
        if [ $ret -ne 0 ]; then
                eerror "${SVCNAME} cannot load configuration"
                return 1
        fi

        $VARNISHADM vcl.use $new_config >/dev/null 2>&1
        ret=$?
        if [ $ret -ne 0 ]; then
                eerror "${SVCNAME} cannot switch configuration"
                return 1
        fi

        eend 0
}

To see what exactly happens, I added set -x to the function and ran /etc/init.d/varnishd reload. The output was:

+ checkconfig
+ /usr/sbin/varnishd -C -f /etc/varnish/default.vcl
+ ret=0
+ '[' 0 -ne 0 ]
+ return 0
+ ebegin 'Reloading varnish'
 * Reloading varnish ...
+ /usr/bin/varnishadm vcl.list
+ ret=0
+ '[' 0 -ne 0 ]
+ date '+%FT%H:%M:%S'
+ new_config=reload_2020-07-14T07:00:41
+ /usr/bin/varnishadm vcl.load reload_2020-07-14T07:00:41 /etc/varnish/default.vcl
+ ret=1
+ '[' 1 -ne 0 ]
+ eerror 'varnishd cannot load configuration'
 * varnishd cannot load configuration
+ return 1
+ exit 1

And if you look at this line:

/usr/bin/varnishadm vcl.load reload_2020-07-14T07:00:41 /etc/varnish/default.vcl

You will see the colons. I reran that command manually, and got the error:

$ /usr/bin/varnishadm vcl.load reload_2020-07-14T07:00:41 /etc/varnish/default.vcl
Illegal character in VCL name (':')
Command failed with error code 106

OK, so the suspected issue is that the parameter to varnish.load contains colons. Let us try the same command but without colons:

$ /usr/bin/varnishadm vcl.load reload_2020-07-14T070041 /etc/varnish/default.vcl
VCL compiled.

Issue confirmed. Now let us fix the code. What we need to change is the call to date +%FT%H:%M:%S. We can replace it with date +%s. The %s format specifier means “seconds since 1970-01-01 00:00:00 UTC”.

Here is the patch:

--- /etc/init.d/varnishd.orig
+++ /etc/init.d/varnishd
@@ -58,7 +58,7 @@
                return 1
        fi

-       new_config="reload_$(date +%FT%H:%M:%S)"
+       new_config="reload_$(date +%s)"
        $VARNISHADM vcl.load $new_config $CONFIGFILE >/dev/null 2>&1
        ret=$?
        if [ $ret -ne 0 ]; then
Alpine 3.11 and Varnish Reload Issue
Tagged on:     

Leave a Reply

Your email address will not be published. Required fields are marked *