CherryPy is a light weight web server/web framework.
Most users trying out CherryPy has probably learned the easy part, running the server script manually and thus starting the server.
Often, the server is placed behind for example an nginx or apache installation.
Running CherryPy with cherryd
' has become a pretty competent web server in the later versions, many times users just want to run it standalone.
The biggest reason is obvious, simplicity, but also keeping the server implementation lightweight.
Normally, running means that you want to run the application as a daemon/service. There are several different ways of doing this, this text will be about using cherryd.
This is how MBE_Front_end is run:
python3 /usr/local/bin/cherryd -c config_standalone.ini -i cherrypy_server -p /var/lock/mbe_demo -d
Parameters used here:
- -c - the config file
- -i - what module to load
- -p - what pid-file to create
- -d - run as a daemon.
Note: The .pid is not bad, the resulting process is just "python", so it could be a good thing to know which to kill.
There is an important difference from just running , cherrypy_server.py directly; cherryd doesn't *run* the script, it *imports* it.
This means that the cherrypy server is started by cherryd, not some start up function like [start_server()].
So how do we avoid that the code is run when cherryd imports it? Well, when run by the interpreter, the __name__ variable is set to "__main__".
Hence the solution is to initialize for standalone then __name__ == "__main__" and for cherryd when it is not.
In the referred script, as much as possible is put in the ini.files. And in the cherryd command line example above, it is the standalone config file that is used.
But as this particular example has to be able to find its certificates and that their locations are relative the position of the script, they are set inside the application.
For normal usage, these settings would also be put in the ini-file .