I have a command line python application that is a service, i.e. expects connections and does something when asked, for example, a web server. There is a python-daemonlibrary for solving all the problems of disconnecting from the terminal, branching, etc., but I would like to go a little further - so that the program performs the following actions:
- Know if it is already running or not (by checking the PID file)
- When called with the "start" parameter, it should start the daemon if it is not running, or report the PID of the existing one and exit if it is running.
- When called with the "stop" option, it must kill the executable instance, if one exists, and clear the PID file.
- When called with the "restart" parameter, it should "stop" and then "start"
- When called with the "status" parameter, it should display the PID of the executable instance or nothing if it does not work.
If this sounds like a standard Unix service, this is exactly what I want. Is there a Python library that implements such a template?
source
share