Debug Varnish 4.x on systemd That Fails to Start

Tired of the privacy invasion of browsers? Worried about the risk of seeing ads everywhere? Give the Brave Browser a try. All Chrome extensions are compatible. None of the telemetry. Auto-blocks ads and still support content creators like me.

Download the Brave browser now »

Profile image of Mattias Geniar

Mattias Geniar, March 15, 2015

Follow me on Twitter as @mattiasgeniar

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!



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.