I have a tool which I have written in python and generally should be run as a daemon. What are the best practices for packaging this tool for distribution, particularly how sho
This blog entry made it clear for me that there are actually two common ways to have your Python program run as a deamon (I hadn't figured that out so clearly from the existing answers):
There are two approaches to writing daemon applications like servers in Python.
- The first is to handle all the tasks of sarting and stopping daemons in Python code itself. The easiest way to do this is with the
python-daemon
package which might eventually make its way into the Python distribution.
Poeljapon's answer is an example of this 1st approach, although it doesn't use the python-daemon
package, but links to a custom but very clean python script.
- The other approach is to use the tools supplied by the operating system. In the case of Debain, this means writing an init script which makes use of the
start-stop-daemon
program.
Ali Afshar's answer is a shell script example of the 2nd approach, using the start-stop-daemon
.
The blog entry I quoted has a shell script example, and some additional details on things such as starting your daemon at system startup and restarting your daemon automatically when it stopped for any reason.