我有一個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