CherryPy Recipes / deployment / supervisor_ /

# -*- coding: utf-8 -*-
""" Basic recipe to demonstrate how to integrate
CherryPy with supervisord:

In order to rest this recipe, install supervisord and run

 $ supervisord -c supervisord.conf
 $ supervisorctl update

Then go to http://localhost:8090/

You will see the PID of the running Python processor.

Click on the provided link that will trigger the
shutdown of the server and fake an error by exiting
with code number of 1.

After a few seconds go back to http://localhost:8090/
and see if the PID has changed (it should).

To confirm this, read the error.log as well.

You may shutdown supervisor as follow:

 $ supervisorctl shutdown
import sys
import os
import time

import cherrypy

def shutdown():
    while True:
        if SHUTDOWN_FLAG:
            cherrypy.log("Aborting server...")
class Root(object):
    def index(self):
        return """<html>
<head />
    <p>CURRENT PROC ID: %d</p>

    <p><a href="/abort">Fake a failure</a> of the process so that supervisord restarts it...</p>

    <p>Once you have done so, simply come back to this page after a few seconds.</p>
</html>""" % os.getpid()

    def abort(self):
        global SHUTDOWN_FLAG
        SHUTDOWN_FLAG = True
if __name__ == '__main__':
    cherrypy.config.update({'server.socket_port': 8090,
                            'engine.autoreload_on': False,
                            'log.access_file': './access.log',
                            'log.error_file': './error.log'})
    t = cherrypy.engine.start_with_callback(shutdown)
    cherrypy.log("Server now down. Let's quit messily...")
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.