views:

185

answers:

3

I'm running Django on Linux using fcgi and Lighttpd. Every now and again (about once a day) the server just dies. I'm using the latest stable release of Django, Python and Lighttpd.

The only thing I can think of is that my program is opening a lot of files and executing a lot of external processes, but I'm fairly sure that side of things is watertight.

Looking at the error and access logs, there's nothing exceptional happening (i.e. load isn't above normal). On those occasions where I have had exceptions from Python, these have shown up in the error.log, but when this crash happens I get nothing.

Is there any way of finding out why the process died? Short of putting logging statements on every single line? Obviously I can't reproduce this so I don't know exactly where to look.

Edit

It's the django process that's dying. I'm running the server with manage.py runfcgi daemonize=true method=threaded host=127.0.0.1 port=12345

+1  A: 

You could edit manage.py to redirect stderr to a file, assuming runfcgi doesn't do that itself:

import sys
if sys.argv[1] == "runfcgi":
    sys.stderr = open("/path/to/my/django-error.log", "a")
Mike DeSimone
Thanks for the suggestion. I think that as I was getting various exceptions in lighttpd's error.log (for unrelated reasons), stderr is already logged. Suffice it to say, the log is empty when the process dies.
Joe
A: 

Is this on your server? (do you own the box?). I've had that problem on shared hosting, and the host was just killing long processes. Do you know if your fcgi is receiving a SIGTERM?

Jared Forsyth
Do you know what process would be sending those messages?It's my [virtual] box. I have a couple of Django processes. This is the only one dying.
Joe
A: 

Have had the same problems. Not only do they die without warning or reason they leak like crazy too with threads being stuck without a master process. We solved this problem by having a cronjob run every 5 minutes that checks if the port number is up and running and if not restart.

By the way, we've now (slowly migrating) given up on fcgi and moved over to uwsgi.

Peter Bengtsson
I came to the same conclusion but with a 1 minute interval. Has uwsgi solved your problem?
Joe
Don't know yet. Haven't seen it crash yet at least.
Peter Bengtsson