make restart dependent on existence of PICKFILE
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user