diff --git a/hbd b/hbd index a1c4173..d1b63d0 100755 --- a/hbd +++ b/hbd @@ -43,13 +43,16 @@ msgwB = None msgwHeight = 10 def handler(signum, frame): - global up, sig - if up == 0: - return + global running, sig sig = signum + if not running: + if verbose: + print "NOT runing signal: %s running: %d" % (sig, running) + return +# signal.signal(sig, handler) if verbose: - print "signal: %s up: %d" % (sig, up) - up = 0 + print "signal: %s running: %s frame: %s" % (sig, running, frame) + running = False # sys.exit(0) @@ -216,6 +219,8 @@ def addhost(name, addr): def on_exit(): if visual: exitcurses() + if DEBUG: + sys.stderr.write("on_exit\n") logf.close() print "exit" @@ -607,9 +612,13 @@ class HtmlHandler(SocketServer.BaseRequestHandler): def saveandrestart(): + if DEBUG: sys.stderr.write("mark 1\n") 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() + if DEBUG: sys.stderr.write("mark 4\n") log("restarting") os.execv(sys.argv[0], [sys.argv[0]]+cmdargs) @@ -636,7 +645,7 @@ cmdargs = [] configfile = "%s/.hbrc" % home try: - optlist, args = getopt.getopt(sys.argv[1:], 'c:dfh:v') + optlist, args = getopt.getopt(sys.argv[1:], 'c:dfh:vx') except: helpflag = True @@ -655,17 +664,20 @@ for o, a in optlist: elif o == '-v': verbose = True cmdargs += [o] + elif o == '-x': + DEBUG = True if helpflag: print "hbc HeartBeatDaemon" - print "usage: hbd [-dfhv] [-c configfile]" + print "usage: hbd [-dfhvx] [-c configfile]" print print " -c configfile" print " -d display" print " -f run in foreground" print " -h this help" print " -v verbose" + print " -x debug" print print """ config file can contain logfile = /var/log/heartbeat.log @@ -800,14 +812,14 @@ if not forground: os.setsid() os.umask(0) -up = 1 +running = True sig = 0 signal.signal(signal.SIGTERM, handler) signal.signal(signal.SIGHUP, handler) next = int(now)+15 # 15 seconds time to settle after (re-)start sleep = next - now -while up: +while running: if visual: c = stdscr.getch() if c == ord('c'): @@ -824,6 +836,8 @@ while up: # elif c == ord('x'): # x = y = 0 + if DEBUG: + sys.stderr.write("about to sleep = %s\n" % (sleep)) try: sr = select.select(ilist, [], [], sleep) now = time.time() @@ -839,6 +853,8 @@ while up: initcurses() display() continue + except: + sys.exit(1) for fh in sr[0]: if fh == sock: readsock() @@ -861,4 +877,6 @@ while up: if sig == signal.SIGHUP: + if DEBUG: + sys.stderr.write("signal 1 exit\n") saveandrestart()