Earlier this year I installed a new Varnish cluster on Ubuntu 16.04 servers. Cool, the (back then) newest version 4.1 already came from the Ubuntu standard repositories.
From older systems - Varnish 3.x and 4.0, using the Varnish apt repo - running on Ubuntu 14.04 trusty, I knew I had to configure special settings like listening ports, vcl config files or memory allocation (malloc) in /etc/default/varnish. What strange face I made when all my custom configs didn't work in Xenial anymore! But why?
It took me a while to figure it out. It's Systemd which is (by default) the new init system in Debian 8 Jessie and therefore also Ubuntu 16.04 Xenial (which is based on Jessie). The older init systems (sysvinit or upstart) were able to use special configurations or additional daemon parameters from /etc/default/config files. Systemd does not. So where does one put the custom daemon modifications now?
Back then I also opened a Ubuntu bug report on Launchpad back in April 2016 (bug #1573561) to tell Ubuntu developers to remove the /etc/default/varnish file or to at least add some special notes in it, that it will be ignored by Systemd. One of the responses was a good hint, that the custom options should be set in the varnish's systemd service file. That's what I did, directly in /lib/systemd/system/varnish.service. Not a good idea it turned out.
This week I updated Varnish from 4.1.1-1 to the currently newest version (in Varnish's own apt repo) 4.1.3-1~jessie. Luckily this was only on testing environments, because a few hours later I got notified that all headers, Varnish was supposed to set, disappeared. First I suspected a problem with the newer Varnish version or a (new) incompatibility with the vcl but at the end I saw that /lib/systemd/system/varnish.service was overwritten by the new package. All my custom modifications, including which vcl to use, were gone. No wonder the HTTP headers were gone, too.
In order to use custom settings, which will not be overwritten by a package update, one has to create a special Systemd service file for varnish within /etc/systemd/system. In my case I created /etc/systemd/system/varnish.service which completely replaces the system's /lib/systemd/system/varnish.service. Another alternative would be to create a subfolder "/etc/systemd/system/varnish.service.d" and in there create separate conf files which overwrite single lines (for example only "ExecStart").
This is how my /etc/systemd/system/varnish.service now looks:
root@xenial:~# cat /etc/systemd/system/varnish.service
Description=Varnish HTTP accelerator
ExecStart=/usr/sbin/varnishd -j unix,user=vcache -F -a :6081 -T localhost:6082 -f /etc/varnish/myapp.vcl -S /etc/varnish/secret -s malloc,4096m
It basically looks exactly the same as the varnish.service file coming from the varnish package from the Ubuntu repositories - only the ExecStart line differs. However it does look very different to the varnish.service file which comes from the varnish packages installed from the Varnish repository!
After this, Systemd needs to be told to learn about the new varnish.service file:
root@xenial:~# systemctl daemon-reload
No comments yet.
Personal Internet VMware PHP Linux Shell Bluecoat Proxy Windows Hardware Virtualization Nagios MySQL DB Monitoring Mail Android Network Wyse Hacks Tomcat Postgres Apple Mac Backup BSD ZFS Solaris SmartOS Unix Multimedia Perl Database MongoDB CMS OTRS FreeBSD Wordpress LXC Nginx Proxmox DNS Graphics GlusterFS Security Chef HAProxy Icinga Ansible HTML MariaDB Containers Rancher Docker AWS ELK Kibana Logstash Filebeat Varnish PGSQL PostgreSQL ElasticSearch CouchDB Bash Macintosh Container Minio Grafana InfluxDB Databases NFS OSSEC SystemD Java Zoneminder Surveillance Elasticsearch SSL TLS Icingaweb2 Cloud Wireless Kubernetes Ubuntu