From e0c662060521ba731676fa1ec19ff963e9fccec1 Mon Sep 17 00:00:00 2001 From: andreas Date: Sat, 21 Aug 2010 12:35:37 +0000 Subject: [PATCH] make restart dependent on existence of PICKFILE --- hbd | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/hbd b/hbd index 994e244..213b7f8 100755 --- a/hbd +++ b/hbd @@ -1,5 +1,5 @@ #!/usr/bin/env python -# $Id: hbd,v 1.21 2010/08/21 12:29:33 andreas Exp $ +# $Id: hbd,v 1.22 2010/08/21 12:35:37 andreas Exp $ # Wait for heartbeat messages and act on them (or their absence) # import time, os, string, sys, socket, atexit, select, SocketServer, getopt, signal, cPickle @@ -7,6 +7,7 @@ import time, os, string, sys, socket, atexit, select, SocketServer, getopt, sign False=0 True=1 LOGFILE="/home/andreas/public_html/messages/andreas" +PICKFILE="/tmp/hbd.pick" hosts={} htab={} @@ -35,10 +36,10 @@ msgwHeight=10 def handler(signum, frame): global up, sig - sig=signum - if verbose: print "signal: %s up: %d" % (sig, up) if up == 0: return + sig=signum + if verbose: print "signal: %s up: %d" % (sig, up) up=0 # sys.exit(0) @@ -445,7 +446,7 @@ cmdargs=[] configfile="%s/.hbrc" % home try: - optlist, args = getopt.getopt(sys.argv[1:], 'c:dfhR:v') + optlist, args = getopt.getopt(sys.argv[1:], 'c:dfh:v') except: helpflag=True @@ -461,8 +462,6 @@ for o,a in optlist: cmdargs+=[o] elif o == '-h': helpflag=True - elif o == '-R': - restart=a elif o == '-v': verbose=True cmdargs+=[o] @@ -544,14 +543,14 @@ if len(args) != 0: if verbose: print "notice: logging to %s" % logfile logf=initlog(logfile) -if restart: - pickf=open(restart, 'r') +if os.path.exists(PICKFILE): + pickf=open(PICKFILE, 'r') pick=cPickle.Unpickler(pickf) hosts=pick.load() htab=pick.load() msgs=pick.load() pickf.close() - os.unlink(restart) + os.unlink(PICKFILE) now=time.time() startsec=int(now) % interval @@ -650,12 +649,12 @@ while up: if sig == signal.SIGHUP: sock.close() serv.socket.close() - pickf=open("/tmp/pick1", 'w') + pickf=open(PICKFILE, 'w') pick=cPickle.Pickler(pickf) pick.dump(hosts) pick.dump(htab) pick.dump(msgs) pickf.close() - os.execv(sys.argv[0],cmdargs+['-R', "/tmp/pick1"]) + os.execv(sys.argv[0],cmdargs)