From 6d3ccd0b4cc378a2cce5b01a8cd1968f8b3a1a20 Mon Sep 17 00:00:00 2001 From: andreas Date: Thu, 5 Apr 2007 15:51:13 +0000 Subject: [PATCH] handle command line flags properly on restart warnings are verbose --- hbc | 4 ++-- hbd | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/hbc b/hbc index f8d3411..b1e64ea 100755 --- a/hbc +++ b/hbc @@ -1,5 +1,5 @@ #!/usr/bin/env python -# $Id: hbc,v 1.6 2006/04/28 12:13:39 andreas Exp $ +# $Id: hbc,v 1.7 2007/04/05 15:51:13 andreas Exp $ import sys, time, socket, os, signal, getopt, string PORT=50003 @@ -85,7 +85,7 @@ try: f=open(configfile,"r") if verbose: print "notice: using config file %s" % configfile except: - print "warning: running without conifig file: %s" % configfile + if verbose: print "warning: running without conifig file: %s" % configfile f=None if f: diff --git a/hbd b/hbd index d577bfe..18988e0 100755 --- a/hbd +++ b/hbd @@ -1,5 +1,5 @@ #!/usr/bin/env python -# $Id: hbd,v 1.15 2006/11/08 15:42:17 andreas Exp $ +# $Id: hbd,v 1.16 2007/04/05 15:51:13 andreas Exp $ # Wait for heartbeat messages and act on them (or their absence) # import time, os, string, sys, socket, atexit, select, SocketServer, getopt, signal, cPickle @@ -287,6 +287,7 @@ def readsock(): boot=0 shutdown=0 name="unknown" + service="unknown" msg=None interval=0 deltaT=0.0 @@ -432,7 +433,9 @@ restart=None optlist=[] args=[] home=os.environ['HOME'] +cmdargs=[] configfile="%s/.hbrc" % home + try: optlist, args = getopt.getopt(sys.argv[1:], 'c:dfhR:v') except: @@ -441,16 +444,20 @@ except: for o,a in optlist: if o == '-c': configfile=a + cmdargs+=[o, a] if o == '-d': visual=True + cmdargs+=[o] elif o == '-f': forground=True + cmdargs+=[o] elif o == '-h': helpflag=True elif o == '-R': restart=a elif o == '-v': verbose=True + cmdargs+=[o] if helpflag: @@ -536,6 +543,7 @@ if restart: htab=pick.load() msgs=pick.load() pickf.close() + os.unlink(restart) now=time.time() startsec=int(now) % interval @@ -563,8 +571,7 @@ ilist.append(serv.fileno()) if not forground and not restart: pid=os.fork() if pid > 0: - if verbose: - print "daemoinizing... pid=%d" % pid + if verbose: print "daemoinizing... pid=%d" % pid sys.exit(0) verbose=False @@ -642,5 +649,5 @@ if sig == signal.SIGHUP: pick.dump(msgs) pickf.close() - os.execv(sys.argv[0],sys.argv+['-R', "/tmp/pick1"]) + os.execv(sys.argv[0],cmdargs+['-R', "/tmp/pick1"])