diff --git a/hbd b/hbd index 0e0cce2..af10bd4 100755 --- a/hbd +++ b/hbd @@ -1,8 +1,8 @@ #!/usr/bin/env python -# $Id: hbd,v 1.11 2006/04/28 12:53:08 andreas Exp $ +# $Id: hbd,v 1.12 2006/11/07 19:41:11 andreas Exp $ # Wait for heartbeat messages and act on them (or their absence) # -import time, os, string, sys, socket, atexit, select, SocketServer, getopt +import time, os, string, sys, socket, atexit, select, SocketServer, getopt, signal False=0 True=1 @@ -30,6 +30,13 @@ msgw=None msgwB=None msgwHeight=10 +def handler(signum, frame): + global up, sig + sig=signum + if up == 0: + return + sys.exit(0) + class NullDevice: def write(self, s): pass @@ -249,14 +256,13 @@ def log(m, service="heartbeat"): def fromaddr(name, addr, boot, interval): global htab - if not htab.has_key(addr): + if not hosts.has_key(name): addhost(name, addr) - host=hosts[htab[addr]] - if host.name != name: - log("%s changed name to %s" % (host.name, name)) - del hosts[host.name] - host.name=name - hosts[name]=host + host=hosts[name] + if host.addr != addr: + log("%s changed address to %s" % (host.name, addr)) + del htab[host.addr] + host.addr=addr htab[addr]=name host.lastbeat=now @@ -396,7 +402,9 @@ class HtmlHandler(SocketServer.BaseRequestHandler): res.append("

Heartbeat status at %s

" % time.strftime("%H:%M:%S", time.localtime(now))) res.append("") res.append("\n" ) - for h in hosts.keys(): + hosts_sorted=hosts.keys() + hosts_sorted.sort() + for h in hosts_sorted: res.append("\n" % (h, hosts[h].state, hosts[h].addr, hosts[h].uppercent, time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(hosts[h].statetime)))) res.append("
HostStateIP AddrResLast change
%-24s%-7s%-16s%-3s%-17s
") res.append("

") @@ -553,9 +561,14 @@ if not forground: os.setsid() os.umask(0) +up=1 +sig=0 +signal.signal(signal.SIGTERM, handler) +signal.signal(signal.SIGHUP, handler) + next=int(now)+1 sleep=next - now -while 1: +while up: if visual: c = stdscr.getch() if c == ord('c'): msgs=[]; display() @@ -601,3 +614,6 @@ while 1: sleep=0 if DEBUG: sys.stderr.write("sleep=%s next=%s\n" % (sleep, next)) + +if sig == signal.SIGHUP: + os.execv(sys.argv[0],sys.argv+['-R'])