Sam Nazarko

Varnish and Debian

Varnish is a fantastic tool to put in front of a web stack. It lets you cache, load balance, consolidate backends and occasionally make it look like you can write mod_rewrite rules. I’ve noticed that with recent Debian updates, there have been changes to make things more favourable for systemd. These changes would normally be welcomed, but such changes result in configuration settings being overwritten.

Previously, settings used to be defined in /etc/default/varnish, which was a conffile. This would ensure that any changes made wouldn’t be overwritten after Debian updates. However after the move to support systemd natively via /lib/systemd/system/varnish.service, this is no longer the case. To change parameters, you’ll need to edit this file, but also run the risk of them being unexpectedly removed on update.

Fortunately, there’s a simple solution. Use a systemd drop-in, which allows you to override only the parameters you want.

To do this, create a new directory /etc/systemd/systemd/varnish.service.d and create a file called ‘local.conf’. You can then specify your command line arguments passed after ExecStart without needing to define other service parameters.

You can now run systemctl daemon-reload for this to take effect. Now, when Varnish is updated, your local changes will take precedence.

This issue also seems to affect RHEL.

Posted January 16, 2018

Written by Sam Nazarko, a 20s London chap who is an open source developer by night. Follow me on Twitter