make restart dependent on existence of PICKFILE
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env python
|
#!/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)
|
# Wait for heartbeat messages and act on them (or their absence)
|
||||||
#
|
#
|
||||||
import time, os, string, sys, socket, atexit, select, SocketServer, getopt, signal, cPickle
|
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
|
False=0
|
||||||
True=1
|
True=1
|
||||||
LOGFILE="/home/andreas/public_html/messages/andreas"
|
LOGFILE="/home/andreas/public_html/messages/andreas"
|
||||||
|
PICKFILE="/tmp/hbd.pick"
|
||||||
|
|
||||||
hosts={}
|
hosts={}
|
||||||
htab={}
|
htab={}
|
||||||
@@ -35,10 +36,10 @@ msgwHeight=10
|
|||||||
|
|
||||||
def handler(signum, frame):
|
def handler(signum, frame):
|
||||||
global up, sig
|
global up, sig
|
||||||
sig=signum
|
|
||||||
if verbose: print "signal: %s up: %d" % (sig, up)
|
|
||||||
if up == 0:
|
if up == 0:
|
||||||
return
|
return
|
||||||
|
sig=signum
|
||||||
|
if verbose: print "signal: %s up: %d" % (sig, up)
|
||||||
up=0
|
up=0
|
||||||
# sys.exit(0)
|
# sys.exit(0)
|
||||||
|
|
||||||
@@ -445,7 +446,7 @@ cmdargs=[]
|
|||||||
configfile="%s/.hbrc" % home
|
configfile="%s/.hbrc" % home
|
||||||
|
|
||||||
try:
|
try:
|
||||||
optlist, args = getopt.getopt(sys.argv[1:], 'c:dfhR:v')
|
optlist, args = getopt.getopt(sys.argv[1:], 'c:dfh:v')
|
||||||
except:
|
except:
|
||||||
helpflag=True
|
helpflag=True
|
||||||
|
|
||||||
@@ -461,8 +462,6 @@ for o,a in optlist:
|
|||||||
cmdargs+=[o]
|
cmdargs+=[o]
|
||||||
elif o == '-h':
|
elif o == '-h':
|
||||||
helpflag=True
|
helpflag=True
|
||||||
elif o == '-R':
|
|
||||||
restart=a
|
|
||||||
elif o == '-v':
|
elif o == '-v':
|
||||||
verbose=True
|
verbose=True
|
||||||
cmdargs+=[o]
|
cmdargs+=[o]
|
||||||
@@ -544,14 +543,14 @@ if len(args) != 0:
|
|||||||
if verbose: print "notice: logging to %s" % logfile
|
if verbose: print "notice: logging to %s" % logfile
|
||||||
logf=initlog(logfile)
|
logf=initlog(logfile)
|
||||||
|
|
||||||
if restart:
|
if os.path.exists(PICKFILE):
|
||||||
pickf=open(restart, 'r')
|
pickf=open(PICKFILE, 'r')
|
||||||
pick=cPickle.Unpickler(pickf)
|
pick=cPickle.Unpickler(pickf)
|
||||||
hosts=pick.load()
|
hosts=pick.load()
|
||||||
htab=pick.load()
|
htab=pick.load()
|
||||||
msgs=pick.load()
|
msgs=pick.load()
|
||||||
pickf.close()
|
pickf.close()
|
||||||
os.unlink(restart)
|
os.unlink(PICKFILE)
|
||||||
|
|
||||||
now=time.time()
|
now=time.time()
|
||||||
startsec=int(now) % interval
|
startsec=int(now) % interval
|
||||||
@@ -650,12 +649,12 @@ while up:
|
|||||||
if sig == signal.SIGHUP:
|
if sig == signal.SIGHUP:
|
||||||
sock.close()
|
sock.close()
|
||||||
serv.socket.close()
|
serv.socket.close()
|
||||||
pickf=open("/tmp/pick1", 'w')
|
pickf=open(PICKFILE, 'w')
|
||||||
pick=cPickle.Pickler(pickf)
|
pick=cPickle.Pickler(pickf)
|
||||||
pick.dump(hosts)
|
pick.dump(hosts)
|
||||||
pick.dump(htab)
|
pick.dump(htab)
|
||||||
pick.dump(msgs)
|
pick.dump(msgs)
|
||||||
pickf.close()
|
pickf.close()
|
||||||
|
|
||||||
os.execv(sys.argv[0],cmdargs+['-R', "/tmp/pick1"])
|
os.execv(sys.argv[0],cmdargs)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user