我有一个python脚本,我daemonise使用此代码守护死亡意外
def daemonise():
from os import fork, setsid, umask, dup2
from sys import stdin, stdout, stderr
if fork(): exit(0)
umask(0)
setsid()
if fork(): exit(0)
stdout.flush()
stderr.flush()
si = file('/dev/null', 'r')
so = file('daemon-%s.out'%os.getpid(), 'a+')
se = file('daemon-%s.err'%os.getpid(), 'a+')
dup2(si.fileno(), stdin.fileno())
dup2(so.fileno(), stdout.fileno())
dup2(se.fileno(), stderr.fileno())
print 'this file has the output from daemon%s'%os.getpid()
print >> stderr, 'this file has the errors from daemon%s'%os.getpid()
脚本是
while True: try: funny_code(); sleep(10); except:pass;
循环。它运行良好几个小时,然后意外死亡。我怎么去调试这些恶魔,错误的守护进程。
[编辑]
无需启动一个过程是怎样的monit的,有没有用Python语言编写一个看门狗,这可以看我的其他守护进程,并重新启动时,他们往下走的方法吗? (谁在监视看门狗。)
我可能会添加一些像monit监视,但我想调试,为什么它失败如此频繁。 daemontools ...以及由djb编写的,所以我只是谨慎的配置它将要求。 :) – agiliq 2009-10-21 11:03:29
@usaretech:不是这次 - 你只需创建一个名为“run”的脚本文件夹。这是一项服务。 – nosklo 2009-10-21 11:27:05