Managing of Varnish backends

This article explains how you can manage Varnish backends from command line, check varnish backend health status and mark backends as healthy or sick without restarting or reloading Varnish.

Check Varnish backend health status

To see all backends, there are 2 methods: a debug output and a normalized output.

The backend.list shows all backends, even those without a probe (= healtcheck) configured.

The command will show in-depth statistics on the varnish probes that are being executed, including the IPv4 connect state, whether a send/receive has worked and if the response code was HTTP/200.

For instance, a healthy backend will be shown like this, with each state of the check (IPv4, send, receive & HTTP response code) on a seperate line.

Now, to change backend statuses.

Mark a varnish backend as healthy or sick

In order to mark a particular backend as sick or healthy, thus overriding the probe, you can do so like this.

The above command will mark the backend named backend1 as healthy. Likewise, you can mark a backend as sick to prevent it from getting traffic.

If you have multiple Varnish backends and they’re configured in a director to load balance traffic, all traffic should gracefully be sent to the other backend(s). (see the examples in mattiasgeniar/varnish-4.0-configuration-templates)

If you mark a backend explicitly as sick, the backend.list output changes and the admin column removes the ‘probe’ and marks it as ‘sick’ explicitly, indicating it was changed via CLI.

You can also change it back to let Varnish decide the backend health.

Mark the backend as ‘varnish managed’, let probes decide the health

To let Varnish decide the health itself, by using it probes, mark the backend to be auto again:

So to summarise: the backend.set_healthy command in varnishadm allows you to manipulate the backend health state of varnish backends, overriding the result of a probe.

Useful when you’re trying to gracefully update several backend servers, by marking backends as sick one by one without waiting for the probes to discover that backends are sick. This method allows you to do things gracefully before the update.

Want me to do this for you? Drop me a line: itgalaxyzzz {at} gmail [dot] com