Commit 59ad6b8b authored by Michel Pelletier's avatar Michel Pelletier

added psychotic fork in a fork file redirection detachment madness

parent 94f21fc9
...@@ -138,9 +138,12 @@ VERBOSE = 1 ...@@ -138,9 +138,12 @@ VERBOSE = 1
# activities = (('http://localhost:9222/Heart/heart', 'michel', '123'), # activities = (('http://localhost:9222/Heart/heart', 'michel', '123'),
# ) # )
import zLOG
def pstamp(message): #this is a bit of a hack so I dont have to change too much code
print "zdeamon: %s: %s" % (time.ctime(time.time()), message) def pstamp(message, sev):
zLOG.LOG("zdeamon", sev,
("zdeamon: %s: %s" % (time.ctime(time.time()), message)))
def heartbeat(): def heartbeat():
print 'tha-thump' print 'tha-thump'
...@@ -149,11 +152,12 @@ def heartbeat(): ...@@ -149,11 +152,12 @@ def heartbeat():
try: try:
result = ZPublisher.Client.call(a[0], a[1], a[2]) result = ZPublisher.Client.call(a[0], a[1], a[2])
except: except:
pstamp('activity %s failed!' % a[0]) pstamp('activity %s failed!' % a[0], zLOG.WARNING)
return return
if result and VERBOSE: if result and VERBOSE:
pstamp('activity %s returned: %s' % (a[0], result)) pstamp('activity %s returned: %s' % (a[0], result),
zLOG.BLATHER)
def forkit(attempts = FORK_ATTEMPTS): def forkit(attempts = FORK_ATTEMPTS):
...@@ -163,14 +167,27 @@ def forkit(attempts = FORK_ATTEMPTS): ...@@ -163,14 +167,27 @@ def forkit(attempts = FORK_ATTEMPTS):
try: try:
pid = os.fork() pid = os.fork()
except os.error: except os.error:
pstamp('Houston, the fork failed') pstamp('Houston, the fork failed', zLOG.ERROR)
time.sleep(2) time.sleep(2)
else: else:
pstamp('Houston, we have forked') pstamp('Houston, we have forked', zLOG.INFO)
return pid return pid
def run(argv, pidfile=''): def run(argv, pidfile=''):
if os.environ.has_key('ZDEAMON_MANAGED'): return if os.environ.has_key('ZDEAMON_MANAGED'):
# We're the child at this point. Don't ask. :/
sys.stdin.close()
sys.stdout.close()
sys.stderr.close()
try:
sys.stdin = open('/dev/null', "r")
sys.stdout = open('/dev/null', "r+")
sys.stderr = open('/dev/null', "r+")
except:
zLOG.LOG("z2", zLOG.ERROR, "couldn't close standard files")
return
os.environ['ZDEAMON_MANAGED']='TRUE' os.environ['ZDEAMON_MANAGED']='TRUE'
while 1: while 1:
lastt=time.time() lastt=time.time()
...@@ -182,7 +199,7 @@ def run(argv, pidfile=''): ...@@ -182,7 +199,7 @@ def run(argv, pidfile=''):
elif pid: elif pid:
# Parent # Parent
pstamp(('Hi, I just forked off a kid: %s' % pid)) pstamp(('Hi, I just forked off a kid: %s' % pid), zLOG.INFO)
# here we want the pid of the parent # here we want the pid of the parent
if pidfile: if pidfile:
pf = open(pidfile, 'w+') pf = open(pidfile, 'w+')
...@@ -200,12 +217,13 @@ def run(argv, pidfile=''): ...@@ -200,12 +217,13 @@ def run(argv, pidfile=''):
continue continue
if s: if s:
pstamp(('Aiieee! %s exited with error code: %s' pstamp(('Aiieee! %s exited with error code: %s'
% (p, s))) % (p, s)), zLOG.ERROR)
if time.time()-lastt < 20: if time.time()-lastt < 20:
raise ForkError # We're probably hosed raise ForkError # We're probably hosed
else: else:
raise ForkError raise ForkError
pstamp(('The kid, %s, died on me.' % pid)) pstamp(('The kid, %s, died on me.' % pid),
zLOG.WARNING)
raise KidDiedOnMeError raise KidDiedOnMeError
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment