Red Hat Bugzilla – Bug 1464355
Starting varnishncsa during boot fails
Last modified: 2018-02-27 11:18:58 EST
Description of problem:
We have a server which is running varnishd and varnishncsa for logging. However, during boot varnishncsa fails because varnishd isn't ready, yet.
Version-Release number of selected component (if applicable):
Install varnish, enable varnishncsa with systemctl and reboot
Steps to Reproduce:
1. Install varnish and configure it.
2. systemctl enable varnishncsa
varnishncsa fails during boot.
varnishncsa is running
Logs show the problem:
Jun 22 08:22:04 test systemd: Failed to read PID from file /var/run/varnish.pid: Invalid argument
Jun 22 08:22:04 test systemd: Started Varnish Cache, a high-performance HTTP accelerator.
Jun 22 08:22:04 test systemd: Starting Varnish Cache HTTP accelerator NCSA logging daemon...
zun 22 08:22:04 test varnishd: Platform: Linux,3.10.0-514.21.2.el7.x86_64,x86_64,-sfile,-smalloc,-hcritbit
Jun 22 08:22:04 test systemd: varnishncsa.service: control process exited, code=exited status=1
Jun 22 08:22:04 test systemd: Failed to start Varnish Cache HTTP accelerator NCSA logging daemon.
Jun 22 08:22:04 test systemd: Unit varnishncsa.service entered failed state.
Jun 22 08:22:04 test systemd: varnishncsa.service failed.
Jun 22 08:22:05 test varnishd: child (939) Started
Jun 22 08:22:05 test varnishd: Child (939) said Child starts
Jun 22 08:22:05 test varnishd: Child (939) said SMF.s0 mmap'ed 2147483648 bytes of 2147483648
So it seems to me varnishncsa is started while varnishd is still starting up. Thus, either varnishncsa has to wait or the varnishd start during boot should only return once varnishd is up...
The problem here is that varnishncsa starts too fast, that is, before varnishd has gotten around to open its vsm file. A simple workaround could be just to add a pause to the startup of varnishd like "ExecStartPost=sleep 5" in varnish.service, or just make varnishncsa try restarting until it succeeds, that is "Restart=on-failure" in varnishncsa.service.
A more correct solution would be to figure out some systemd probe-able resource that is not available before varnishd has started proberly, and make varnishncsa wait for that. I've got to look more into this, and ask upstream.
Upstream issue: https://github.com/varnishcache/pkg-varnish-cache/issues/79
I closed the upstream issue because as far as we are concerned, 4.0 is EOL and the verdict is WONTFIX. There's no easy workaround until 4.1 (enabled by default). 5.2 finishes daemonizing when varnishd is completely ready and shouldn't need any workaround.