Debug Varnish 4.x on systemd That Fails to Start

Mattias Geniar, Sunday, March 15, 2015 - last modified: Wednesday, July 27, 2016

So you're stuck in systemctl start varnish, now what?

Well, by default, systemd won't tell you much.

$ systemctl start varnish
Job for varnish.service failed. See 'systemctl status varnish.service' and 'journalctl -xn' for details.

View the status of the service:

$  systemctl status varnish
varnish.service - Varnish a high-perfomance HTTP accelerator
   Loaded: loaded (/usr/lib/systemd/system/varnish.service; enabled)
   Active: failed (Result: exit-code) since Sun 2015-03-15 21:07:41 CET; 15s ago
  Process: 10062 ExecStart=/usr/sbin/varnishd -P /var/run/varnish.pid -f $VARNISH_VCL_CONF -a ${VARNISH_LISTEN_ADDRESS}:${VARNISH_LISTEN_PORT} -T ${VARNISH_ADMIN_LISTEN_ADDRESS}:${VARNISH_ADMIN_LISTEN_PORT} -t $VARNISH_TTL -u $VARNISH_USER -g $VARNISH_GROUP -S $VARNISH_SECRET_FILE -s $VARNISH_STORAGE $DAEMON_OPTS (code=exited, status=2)
  Process: 10049 ExecStartPre=/usr/sbin/varnishd -C -f $VARNISH_VCL_CONF (code=exited, status=0/SUCCESS)
 Main PID: 6187 (code=exited, status=0/SUCCESS)

site.be varnishd[10049]: .miss_func = VGC_function_vcl_miss,
site.be varnishd[10049]: .hit_func = VGC_function_vcl_hit,
site.be varnishd[10049]: .deliver_func = VGC_function_vcl_deliver,
site.be varnishd[10049]: .synth_func = VGC_function_vcl_synth,
site.be varnishd[10049]: .backend_fetch_func = VGC_function_vcl_backend_fetch,
site.be varnishd[10049]: .backend_response_func = VGC_function_vcl_backend_response,
site.be varnishd[10049]: .backend_error_func = VGC_function_vcl_backend_error,
site.be varnishd[10049]: .init_func = VGC_function_vcl_init,
site.be varnishd[10049]: .fini_func = VGC_function_vcl_fini,
site.be varnishd[10049]: };

It'll show the message that Varnish failed to start, and it will show the last 10 lines of output the program sent to stdout/stderr. But in Varnish' case, that's just the compiled VCL and it won't actually tell you the error.

To start, test the syntax of your Varnish 4 VCL file.

$ varnishd -d -f /etc/varnish/default.vcl
...
-----------------------------
Varnish Cache CLI 1.0
-----------------------------
...

If you see a "Varnish Cache CLI", your VCL compiled and is working. That means the problem could be in the way systemd starts its service.

$ grep systemd /var/log/messages
Mar 15 21:07:41 lb01 systemd: Starting Varnish a high-perfomance HTTP accelerator...
Mar 15 21:07:41 lb01 systemd: varnish.service: control process exited, code=exited status=2
Mar 15 21:07:41 lb01 systemd: Failed to start Varnish a high-perfomance HTTP accelerator.
Mar 15 21:07:41 lb01 systemd: Unit varnish.service entered failed state.

So in this case, systemd failed to start the service with my requested parameters. Check your varnish.service in /usr/lib/systemd/system/varnish.service file for any typos or mis-configured environment variables and try again!



Hi! My name is Mattias Geniar. I'm a Support Manager at Nucleus Hosting in Belgium, a general web geek & public speaker. Currently working on DNS Spy & Oh Dear!. Follow me on Twitter as @mattiasgeniar.

Share this post

Did you like this post? Will you help me share it on social media? Thanks!

Comments

stuartm Wednesday, May 13, 2015 at 02:26 - Reply

Thanks – this post and your related post (https://ma.ttias.be/running-varnish-4-x-on-systemd/) helped me troubleshoot an issue with Varnish 4 on Debian 8. The Varnish service was starting okay, but it wasn’t using my settings in /etc/default/varnish. From your posts I realised that the varnish.service script was not referencing any parameters files (not even the varnish.params you suggested). This is on a clean build of Debian 8 and is reproducible.

(btw – I added your site to my ad-blocker whitelist :-) )


Leave a Reply

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