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!

link|improve this question

62% accept rate
feedback

3 Answers

up vote 0 down vote accepted

You'll be fighting monit forever; I don't recommend anyone use it for anything. A much more robust architecture is something like daemontools.

link|improve this answer
I dont think that he need additional. Just the basic unix commands would do the job. – Istvan Sep 4 '09 at 23:47
Truly spoken like someone who's never spent hours trying to convince monit to agree that a service is in the same state as reality. – womble Sep 5 '09 at 2:37
feedback

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.

link|improve this answer
What OS doesn't clean up sockets from a killed process? – womble Sep 4 '09 at 7:26
1  
i guess you might have problem with understanding what i wrote The idea here is that properly written programs will respond to a -15 by cleaning up anything they need to do before dying. immediately. A "kill -9" just causes the process to die; it gets no chance to do any cleanup. Therefore, if you don't know how a program was written, you should try the -15 first, in case it does need to clean up files, flush logs or whatever. en.wikipedia.org/wiki/Functional_illiteracy – Istvan Sep 4 '09 at 23:50
OK, to put it another way: what OS will leave sockets open from a process that is killed with -9? – womble Sep 5 '09 at 2:36
feedback

I have a similar problem when restarting nginx. I use something like this:

/etc/init.d/nginx stop
sleep 2
/etc/init.d/nginx start

And it works

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.