remove serv.shutdown() as we donr use the library service loop

This commit is contained in:
2013-10-25 14:45:10 -04:00
parent 6fe24e8c59
commit f8568dba7e
+28 -10
View File
@@ -43,13 +43,16 @@ msgwB = None
msgwHeight = 10 msgwHeight = 10
def handler(signum, frame): def handler(signum, frame):
global up, sig global running, sig
if up == 0:
return
sig = signum sig = signum
if not running:
if verbose: if verbose:
print "signal: %s up: %d" % (sig, up) print "NOT runing signal: %s running: %d" % (sig, running)
up = 0 return
# signal.signal(sig, handler)
if verbose:
print "signal: %s running: %s frame: %s" % (sig, running, frame)
running = False
# sys.exit(0) # sys.exit(0)
@@ -216,6 +219,8 @@ def addhost(name, addr):
def on_exit(): def on_exit():
if visual: if visual:
exitcurses() exitcurses()
if DEBUG:
sys.stderr.write("on_exit\n")
logf.close() logf.close()
print "exit" print "exit"
@@ -607,9 +612,13 @@ class HtmlHandler(SocketServer.BaseRequestHandler):
def saveandrestart(): def saveandrestart():
if DEBUG: sys.stderr.write("mark 1\n")
sock.close() sock.close()
serv.shutdown() # if DEBUG: sys.stderr.write("mark 2\n")
# serv.shutdown() #N.B. dont shutdown() as we don't use serv_forever
if DEBUG: sys.stderr.write("mark 3\n")
serv.server_close() serv.server_close()
if DEBUG: sys.stderr.write("mark 4\n")
log("restarting") log("restarting")
os.execv(sys.argv[0], [sys.argv[0]]+cmdargs) os.execv(sys.argv[0], [sys.argv[0]]+cmdargs)
@@ -636,7 +645,7 @@ cmdargs = []
configfile = "%s/.hbrc" % home configfile = "%s/.hbrc" % home
try: try:
optlist, args = getopt.getopt(sys.argv[1:], 'c:dfh:v') optlist, args = getopt.getopt(sys.argv[1:], 'c:dfh:vx')
except: except:
helpflag = True helpflag = True
@@ -655,17 +664,20 @@ for o, a in optlist:
elif o == '-v': elif o == '-v':
verbose = True verbose = True
cmdargs += [o] cmdargs += [o]
elif o == '-x':
DEBUG = True
if helpflag: if helpflag:
print "hbc HeartBeatDaemon" print "hbc HeartBeatDaemon"
print "usage: hbd [-dfhv] [-c configfile]" print "usage: hbd [-dfhvx] [-c configfile]"
print print
print " -c configfile" print " -c configfile"
print " -d display" print " -d display"
print " -f run in foreground" print " -f run in foreground"
print " -h this help" print " -h this help"
print " -v verbose" print " -v verbose"
print " -x debug"
print print
print """ config file can contain print """ config file can contain
logfile = /var/log/heartbeat.log logfile = /var/log/heartbeat.log
@@ -800,14 +812,14 @@ if not forground:
os.setsid() os.setsid()
os.umask(0) os.umask(0)
up = 1 running = True
sig = 0 sig = 0
signal.signal(signal.SIGTERM, handler) signal.signal(signal.SIGTERM, handler)
signal.signal(signal.SIGHUP, handler) signal.signal(signal.SIGHUP, handler)
next = int(now)+15 # 15 seconds time to settle after (re-)start next = int(now)+15 # 15 seconds time to settle after (re-)start
sleep = next - now sleep = next - now
while up: while running:
if visual: if visual:
c = stdscr.getch() c = stdscr.getch()
if c == ord('c'): if c == ord('c'):
@@ -824,6 +836,8 @@ while up:
# elif c == ord('x'): # elif c == ord('x'):
# x = y = 0 # x = y = 0
if DEBUG:
sys.stderr.write("about to sleep = %s\n" % (sleep))
try: try:
sr = select.select(ilist, [], [], sleep) sr = select.select(ilist, [], [], sleep)
now = time.time() now = time.time()
@@ -839,6 +853,8 @@ while up:
initcurses() initcurses()
display() display()
continue continue
except:
sys.exit(1)
for fh in sr[0]: for fh in sr[0]:
if fh == sock: if fh == sock:
readsock() readsock()
@@ -861,4 +877,6 @@ while up:
if sig == signal.SIGHUP: if sig == signal.SIGHUP:
if DEBUG:
sys.stderr.write("signal 1 exit\n")
saveandrestart() saveandrestart()