make work on linux

This commit is contained in:
2016-04-19 18:17:17 -04:00
2 changed files with 203 additions and 101 deletions
+14 -4
View File
@@ -33,7 +33,7 @@ import syslog
PORT = 50003
INTERVAL = 10
PIDFILE = '/tmp/hbc.pid'
DBG = True
DBG = False
sock = None
up = True
@@ -54,13 +54,16 @@ def getsock(host):
try:
r=socket.getaddrinfo(host, 50001, 0, 0, socket.SOL_UDP)
except socket.gaierror:
logm = '%s hbc died: \n%s' % ('getsock', traceback.format_exc())
if DBG: print logm
return None
if r[0][0] == 28:
if r[0][0] in [10, 28, 30]:
af_type=socket.AF_INET6
elif r[0][0] == 2:
af_type=socket.AF_INET
else:
return None
print "dont know this net type: %s" % r[0][0]
sys.exit(1)
if verbose:
syslog.syslog("socktype: %s" % af_type)
sock=socket.socket(af_type, socket.SOCK_DGRAM)
@@ -76,6 +79,7 @@ def socksend(msg, tohost):
if sock == None:
sock=getsock(tohost[0])
if DBG: print "socksend: sending msg=%s on socket=%s" % (msg, sock)
sock.sendto(msg, tohost)
if verbose: syslog.syslog("msg %s sent" % msg)
@@ -117,6 +121,8 @@ def process():
if verbose: syslog.syslog("sock.send('%s', (%s, %s))" % (msg, hb_host, hb_port))
socksend(msg, (hb_host, hb_port))
except:
logm = '%s hbc died: \n%s' % ('socksend', traceback.format_exc())
if DBG: print logm
pass
@@ -241,6 +247,7 @@ if not msgonly:
msgboot.append("interval=%s" % interval)
if len(msgboot) > 0:
if DBG: print "on boot"
msgboot.append("name=%s" % iam)
msgboot.append("time=%s" % time.time())
msgboot.append("acks=0")
@@ -249,9 +256,11 @@ if len(msgboot) > 0:
fail=0
for hb_host in hb_hosts:
try:
if verbose: print "sock.send('%s', (%s, %s))" % (msg, hb_host, hb_port)
if DBG: print "sock.send('%s', (%s, %s))" % (msg, hb_host, hb_port)
socksend(msg, (hb_host, hb_port))
except:
logm = '%s hbc died: \n%s' % ('socksend2', traceback.format_exc())
if DBG: print logm
fail=1
if fail:
time.sleep(10)
@@ -293,6 +302,7 @@ if fdaemon:
working_directory='/tmp',
umask=0o002,
pidfile=pidfile,
initgroups=False,
)
context.signal_map = {