python unix service library
I have a command-line python app that is a service - i.e. it waits for connections and does stuff when asked, like webserver. There's python-daemon
library for dealing with all the issues of detaching from the terminal, forking, etc. but I'd like to go a bit further - to have the开发者_如何学JAVA program do the following:
- Know if it's already running or not (by checking the PID file)
- When called with 'start' option it should start the daemon if it's not running, or tell the PID of existing one and exit if running.
- When called with 'stop' option it should kill the running instance if it exist, and clean the PID file.
- When called with 'restart' option it should do 'stop', then 'start'
- When called with 'status' option it should display the PID of running instance or nothing if it's not running.
If that looks like standard Unix service - that's exactly what I want. Is there a Python library that implements such pattern?
I've used this recipe. Works pretty good.
http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/
精彩评论