Deploying CherryPy (daemon)
Daemonizer can be pretty simple to use:
# this works for cherrypy 3.1.2 on Ubuntu 10.04from cherrypy.process.plugins import Daemonizer# before mounting anythingDaemonizer(cherrypy.engine).subscribe()cherrypy.tree.mount(MyDaemonApp, "/")cherrypy.engine.start()cherrypy.engine.block()
There is a decent HOWTO for SysV style here.
To summarize:
Create a file named for your application in
/etc/init.d
that calls/bin/sh
sudo vim /etc/init.d/MyDaemonApp
#!/bin/sh echo "Invoking MyDaemonApp"; /path/to/MyDaemonApp echo "Started MyDaemonApp. Tremble, Ye Mighty."
Make it executable
sudo chmod +x /etc/init.d/MyDaemonApp
Run
update-rc.d
to create our proper links in the proper runtime dir.sudo update-rc.d MyDaemonApp defaults 80
sudo /etc/init.d/MyDaemonApp
There is a Daemonizer plugin for CherryPy included by default which is useful for getting it to start but by far the easiest way for simple cases is to use the cherryd script:
> cherryd -hUsage: cherryd [options]Options: -h, --help show this help message and exit -c CONFIG, --config=CONFIG specify config file(s) -d run the server as a daemon -e ENVIRONMENT, --environment=ENVIRONMENT apply the given config environment -f start a fastcgi server instead of the default HTTP server -s start a scgi server instead of the default HTTP server -i IMPORTS, --import=IMPORTS specify modules to import -p PIDFILE, --pidfile=PIDFILE store the process id in the given file
As far as an init.d script goes I think there are examples that can be Googled.
And the cherryd
is found in your:
virtualenv/lib/python2.7/site-packages/cherrypy/cherryd
or in: https://bitbucket.org/cherrypy/cherrypy/src/default/cherrypy/cherryd
I wrote a tutorial/project skeleton, cherrypy-webapp-skeleton, which goal was to fill the gaps for deploying a real-world CherryPy application on Debian* for a web-developer. It features extended cherryd
for daemon privilege drop. There's also a number of important script and config files for init.d
, nginx
, monit
, logrotate
. The tutorial part describes how to put things together and eventually forget about it. The skeleton part proposes a way of possible arrangement of CherryPy webapp project assets.
* It was written for Squeeze but practically it should be same for Wheezy.