Proper way to run CherryPy app as a daemon?

Israel Brewster israel at ravnalaska.net
Tue Mar 28 13:25:33 EDT 2017


I am wanting to run a CherryPy app as a daemon on CentOS 6 using an init.d script. By subscribing to the "Daemonizer" and PIDFile cherrypy plugins, I have been able to write an init.d script that starts and stops my CherryPy application. There's only one problem: it would appear that the program daemonizes, thus allowing the init.d script to return a good start, as soon as I call cherrypy.engine.start(), but *before* the cherrypy app has actually started. Particularly, this occurs before cherrypy has bound to the desired port. The end result is that running "service <myapp> start" returns OK, indicating that the app is now running, even when it cannot bind to the port, thus preventing it from actually starting. This is turn causes issues with my clustering software which thinks it started just fine, when in fact it never *really* started.

As such, is there a way to delay the demonization until I call cherrypy.engine.block()? Or some other way to prevent the init.d script from indicating a successful start until the process has actually bound to the needed port and fully started? What is the proper way of doing this? 

Thanks! 
-----------------------------------------------
Israel Brewster
Systems Analyst II
Ravn Alaska
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7293
-----------------------------------------------






More information about the Python-list mailing list