handle command line flags properly on restart

warnings are verbose
This commit is contained in:
andreas
2007-04-05 15:51:13 +00:00
parent 6f2be6b2b9
commit 6d3ccd0b4c
2 changed files with 13 additions and 6 deletions
+2 -2
View File
@@ -1,5 +1,5 @@
#!/usr/bin/env python #!/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 import sys, time, socket, os, signal, getopt, string
PORT=50003 PORT=50003
@@ -85,7 +85,7 @@ try:
f=open(configfile,"r") f=open(configfile,"r")
if verbose: print "notice: using config file %s" % configfile if verbose: print "notice: using config file %s" % configfile
except: except:
print "warning: running without conifig file: %s" % configfile if verbose: print "warning: running without conifig file: %s" % configfile
f=None f=None
if f: if f:
+11 -4
View File
@@ -1,5 +1,5 @@
#!/usr/bin/env python #!/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) # Wait for heartbeat messages and act on them (or their absence)
# #
import time, os, string, sys, socket, atexit, select, SocketServer, getopt, signal, cPickle import time, os, string, sys, socket, atexit, select, SocketServer, getopt, signal, cPickle
@@ -287,6 +287,7 @@ def readsock():
boot=0 boot=0
shutdown=0 shutdown=0
name="unknown" name="unknown"
service="unknown"
msg=None msg=None
interval=0 interval=0
deltaT=0.0 deltaT=0.0
@@ -432,7 +433,9 @@ restart=None
optlist=[] optlist=[]
args=[] args=[]
home=os.environ['HOME'] home=os.environ['HOME']
cmdargs=[]
configfile="%s/.hbrc" % home configfile="%s/.hbrc" % home
try: try:
optlist, args = getopt.getopt(sys.argv[1:], 'c:dfhR:v') optlist, args = getopt.getopt(sys.argv[1:], 'c:dfhR:v')
except: except:
@@ -441,16 +444,20 @@ except:
for o,a in optlist: for o,a in optlist:
if o == '-c': if o == '-c':
configfile=a configfile=a
cmdargs+=[o, a]
if o == '-d': if o == '-d':
visual=True visual=True
cmdargs+=[o]
elif o == '-f': elif o == '-f':
forground=True forground=True
cmdargs+=[o]
elif o == '-h': elif o == '-h':
helpflag=True helpflag=True
elif o == '-R': elif o == '-R':
restart=a restart=a
elif o == '-v': elif o == '-v':
verbose=True verbose=True
cmdargs+=[o]
if helpflag: if helpflag:
@@ -536,6 +543,7 @@ if restart:
htab=pick.load() htab=pick.load()
msgs=pick.load() msgs=pick.load()
pickf.close() pickf.close()
os.unlink(restart)
now=time.time() now=time.time()
startsec=int(now) % interval startsec=int(now) % interval
@@ -563,8 +571,7 @@ ilist.append(serv.fileno())
if not forground and not restart: if not forground and not restart:
pid=os.fork() pid=os.fork()
if pid > 0: if pid > 0:
if verbose: if verbose: print "daemoinizing... pid=%d" % pid
print "daemoinizing... pid=%d" % pid
sys.exit(0) sys.exit(0)
verbose=False verbose=False
@@ -642,5 +649,5 @@ if sig == signal.SIGHUP:
pick.dump(msgs) pick.dump(msgs)
pickf.close() pickf.close()
os.execv(sys.argv[0],sys.argv+['-R', "/tmp/pick1"]) os.execv(sys.argv[0],cmdargs+['-R', "/tmp/pick1"])