Lately I have been trying to use Loggerhead, a simple Bazaar repository viewer which is developed at Launchpad. Bazaar itself is the source code manager behind all the Launchpad projects.
So I needed to serve Loggerhead behind the Cherokee server; but unfortunately, it is not very friendly to non-Apache servers. It runs primarily in WSGI mode (interpreter embedded into the web server). One of Cherokee’s principles is to be lightweight, and therefore it does not support WSGI. So the only option left is to run it standalone and proxy it through Cherokee, which is slow and overall not very good.
Today I tried to get the support I needed myself, and I have found a solution.
Adapting it to Cherokee
FastCGI/SCGI support is a feature which has been asked several times, and officially its users are left without a viable solution right now. FastCGI and SCGI are, in short, internal protocols that Cherokee is able to communicate with.
I knew that *CGI in Django worked with a python library called flup, so I had a quick look at it. Basically it is able to wrap a WSGI application, and make it usable with *CGI. All the API I needed was incredibly simple, a WSGIServer class and the run() method.
I located the entry point of the serve-branches script (it’s in loggerhead/main.py), and copied it to /loggerhead/serve-branches-flup. Then I made it executable, by adding
#!/usr/bin/env python at the top, and these two lines at the bottom:
if __name__ == '__main__': main(sys.argv[1:])
Then we have this line which starts the http server:
httpserver.serve(app, host=host, port=port)
Let’s replace it with the equivalent flup code.
from flup.server.scgi import WSGIServer WSGIServer(app, bindAddress=(host, int(port))).run()
Then I restart Cherokee with the script instead of serve-branches, using the same arguments. It works!
Flup rocks ;)