I have a problem with monit where occasionally Varnish will crash and refuse to start. So Varnish is dead and my webserver is inaccessible. Here's the message from the monit log:
info : 'varnish' stop: /etc/init.d/varnish
info : 'varnish' start: /etc/init.d/varnish
error : monit: Error reading pid from file '/var/run/varnish.pid'
Within the Varnish monitor, I thought of setting an option to restart nginx so it can listen for external requests on port 80 again if something like this happens:
if 3 restarts within 3 cycles
then exec "/etc/init.d/nginx restart"
and timeout
Except when I call that, sometimes nginx stops successfully... but never starts again.
The solutions I've thought of are kind of a hack (kill -9 nginx && /etc/init.d/nginx start) and (killall -9 varnishd && rm -f /var/run/varnish.pid).
I was hoping anyone could offer suggestions to either of the two above problems. Thanks!
never ever use -9 BUT ONLY if you tried -3 and -15 already, it leaves the sockets open and basically the application has no chance to clean up after itself.
You'll be fighting monit forever; I don't recommend anyone use it for anything. A much more robust architecture is something like daemontools.
I have a similar problem when restarting nginx. I use something like this:
And it works