This commit is contained in:
andreas
2005-07-20 14:03:46 +00:00
parent 203f92d61f
commit 2a4be86179
3 changed files with 12 additions and 20 deletions
+3 -2
View File
@@ -1,5 +1,5 @@
#!/usr/bin/env python
# $Id: hbc,v 1.3 2005/07/19 20:31:05 andreas Exp $
# $Id: hbc,v 1.4 2005/07/20 14:03:46 andreas Exp $
import sys, time, socket, os, signal, getopt, string
PORT=50003
@@ -124,6 +124,7 @@ if not msgonly:
if len(msgboot) > 0:
msgboot.append("name=%s" % iam)
msgboot.append("time=%s" % time.time())
msg=string.join(msgboot,";")
while 1:
fail=0
@@ -160,7 +161,6 @@ if daemon:
os.umask(0)
msg="interval=%s;name=%s" % (interval, iam)
up=1
signal.signal(signal.SIGTERM, handler)
signal.signal(signal.SIGHUP, handler)
@@ -172,6 +172,7 @@ while up:
break
for hb_host in hb_hosts:
try:
msg="interval=%s;name=%s;time=%s" % (interval, iam, time.time())
if verbose: print "sock.send('%s', (%s, %s))" % (msg, hb_host, hb_port)
sock.sendto(msg, (hb_host, hb_port))
except:
+9 -3
View File
@@ -1,5 +1,5 @@
#!/usr/bin/env python
# $Id: hbd,v 1.2 2005/07/19 20:31:05 andreas Exp $
# $Id: hbd,v 1.3 2005/07/20 14:03:46 andreas Exp $
# Wait for heartbeat messages and act on them (or their absence)
#
import time, os, string, sys, socket, curses, atexit, select, SocketServer, getopt
@@ -269,6 +269,7 @@ def readsock():
name="unknown"
msg=None
interval=0
deltaT=0.0
for pair in pairs:
l=string.split(pair,"=")
key=l[0]
@@ -288,10 +289,15 @@ def readsock():
msg=val
elif key == 'service':
service=val
elif key == 'time':
try:
deltaT=now-float(val)
except:
pass
if boot:
log("%s booted" % name)
log("%s booted, deltaT %0.2g sec" % (name, deltaT))
if msg:
log("%s msg: %s" % (name, msg),service=service)
log("%s %0.2g msg: %s" % (name, deltaT, msg),service=service)
fromaddr(name, addr[0], boot, interval)
if shutdown:
log("%s shutdown" % name)
-15
View File
@@ -1,15 +0,0 @@
#!/usr/bin/env python
# $Id: hbmsg,v 1.1 2005/07/14 19:28:59 andreas Exp $
import time, socket
ADDR="204.29.161.33"
#ADDR="10.99.1.4"
PORT=50003
SERVICE="service"
iam=socket.gethostname()
sock=socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
msgboot="msg=This is a test;service=%s;name=%s" % (SERVICE, iam)
sock.sendto(msgboot, (ADDR, PORT))
time.sleep(1)
sock.close()