Varnish: Reloading VCL configuration files with varnishadm

Sep 9 2010

Did you know that you can reload varnish VCL configuration files without restarting varnish? While I could find any clear mention of this in the manual, it turns out to be a simple two-step task accomplished using varnishadm.

Prerequisites: Having Varnish Listen for Admin Connections

In order to reload using varnishadm, we need to have the varnishd instance listening for incoming admin connections. Here's an example showing how to start varnishd with an admin listener on localhost:81

Note the -T localhost:81 option. That's what tells Varnish what address and port to listen on.

Reloading a VCL File

Now we can reload the file using varnishadm.

At the console, we connect to our varnishd instance with varnishadm:

$ varnishadm -T localhost:81

From the Varnish admin console, we issue a pair of commands:

vcl.load reload01 /usr/local/etc/varnish/default.vcl
vcl.use reload01

The first line tells varnishd to load and compile the VCL file (/usr/local/etc/varnish/default.vcl), and assign it the name reload01. If we wanted to see a list of all of the named configurations that varnishd currently has, we could use vcl.list.

If the new file loads and compiles okay, we will get a message on the console telling us that that is the case. Now that the file is loaded, we just need to tell Varnish to use that new file. That's what vcl.use is for. It takes as an argument the name of the configuration. In our case, this is reload01.

That's it. Within moments, varnishd should be using the new configuration. <!--break-->