Feb 14, 2012

Supervisord: Stop/Start gunicorn processes with XMLRPC and python

Supervisor: A Process Control System, as stated on supervisor's site. I used it to "supervise" gunicorn services which serves my Django sites.

I have a use case where I need to restart a gunicorn instance from Django itself. Supervisor supports XMLRPC, but instructions to use them weren't very well documented (no examples for lazy me). After some research (google + stackoverflow), I finally figured out how to do so.

As suggested from one of the stackoverflow post, supervisor is pure python implementation, so naturally it will use python libs to implement xmlrpc. That's exactly the codes we need to connect to supervisord's xmlrpc server.

from xmlrpclib import ServerProxy s = ServerProxy("http://localhost:10000") s.supervisor.stopProcess('process1') s.supervisor.startProcess('process1', False)

No comments:

Post a Comment