This Python needs Adult Supervision
A while back, I wrote a daemon. No, I’m not a satanist mom, it’s a program which will basically stick around and manage a bunch of other little minions as they server content via unix sockets to a webserver (nginx).
The point here is to take in traffic from nginx via python and do something with it. For this I found an excellent tutorial which got me started:
http://www.p16blog.com/p16/2008/11/quick-demo-of-python-wsgi-nginx.html
This worked great, but then you needed to write something to manage all the little unix sockets, start them when they died, etc.
So I had to custom write something (at least I thought) as nothing in existence seemed suited for the task. It has worked “okay” but is having some mysterious problems under heavy real world load, and I needed to find something more robust for the task.
I recently stumbled across:
http://just-another.net/2009/01/18/byteflowdjangosupervisordnginx-win/
This thing looks perfect, but I can’t quite get it work… Basically, supervisord is a python application which has a very usefull and usable configuration file to specify programs you would like to run as services. It replaces 90% of the init.d scripts in existence I imagine.
you create a block like this:
In theory,
; Production setup [fcgi-program:gate] socket=tcp://127.0.0.1:1212 ; We reference this later in nginx command = /usr/local/solrflare/bin/gate.py ; Calls the above code
This means, that when I run supervisord, it starts a daemon which will fire up my python script (which currently looks like this):
#!/usr/bin/python
from flup.server.fcgi import WSGIServer
import time, os, sys
def app(environ, start_response):
status = "200 OK"
response_headers = [('Content-type', 'text/plain')]
start_response(status, response_headers)
return ["If a thread dies in the middle of a request, and noone is a around to hear it, does it give a status code?\n"]
WSGIServer(app).run()
And Supervisord provides a nice little web interface to monitor and manage the daemon, also provides a nice interactive shell program and XML-RPC! (among many other cool features).
When this works, it will be awesome because I can throw out a lot of code (which I love to do). However, currently it just kinda sits there when I curl the port… doesn’t do anything, doesn’t log anything.
Update: I got it working! And it is awesome. I just needed to deal w/ an nginx config issue I created and do some permissions wrangling. It is running great so far!


