用python编写daemon监控进程并自动恢复
下面这个程序是用于python编写daemon监控进程并自动恢复,参考http://pythonhosted.org/KiTT/_modules/kitt/daemon.html
#!/usr/bin/env python import sys, os, time, atexit from signal import SIGTERM[docs] class Daemon : """ A generic daemon class. Usage: subclass the Daemon class and override the run() method """ def __init__ ( self , pidfile , stdin = '/dev/null' , stdout = '/dev/null' , stderr = '/dev/null' , args = None ): self . stdin = stdin self . stdout = stdout self . stderr = stderr self . pidfile = pidfile self . args = args[docs] def daemonize ( self ): """ do the UNIX double-fork magic, see Stevens' "Advanced Programming in the UNIX Environment" for details (ISBN 0201563177) http://www.erlenstar.demon.co.uk/unix/faq_2.html#SEC16 """ try : pid = os . fork () if pid > 0 : # exit first parent sys . exit

该博客介绍了一个使用Python编写的daemon程序,该程序能够监控指定进程,并在进程崩溃时自动进行恢复,确保服务的稳定运行。内容来源于http://pythonhosted.org/KiTT/_modules/kitt/daemon.html。
最低0.47元/天 解锁文章
1729

被折叠的 条评论
为什么被折叠?



