[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[minion-cvs] More hacks, and quickie (untested) CLI to start server.



Update of /home/minion/cvsroot/src/minion/lib/mixminion
In directory moria.seul.org:/tmp/cvs-serv4178/lib/mixminion

Modified Files:
	Common.py Queue.py ServerMain.py 
Log Message:
More hacks, and quickie (untested) CLI to start server.

Common:
	Add fatal_exc to compelement error_exc.

Queue:
	Hardwire code to drop messages after 10 tries.

ServerMain:
	CLI interface to start the server.  Not yet tested.


Index: Common.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/Common.py,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- Common.py	21 Aug 2002 19:09:48 -0000	1.15
+++ Common.py	21 Aug 2002 20:49:16 -0000	1.16
@@ -315,21 +315,27 @@
         self.log("ERROR", message, *args)
     def fatal(self, message, *args):
         self.log("FATAL", message, *args)
-    def error_exc(self, (exclass, ex, tb), message=None, *args):
+    def log_exc(self, severity, (exclass, ex, tb), message=None, *args):
 	if message is not None:
-	    self.log("ERROR", message, *args)
+	    self.log(severity, message, *args)
 	elif tb is not None:
 	    filename = tb.tb_frame.f_code.co_filename
-	    self.log("ERROR", "Unexpected exception in %s", filename)
+	    self.log(severity, "Unexpected exception in %s", filename)
 	else:
-	    self.log("ERROR", "Unexpected exception")
+	    self.log(severity, "Unexpected exception")
 	
 	formatted = traceback.format_exception(exclass, ex, tb)
 	formatted[1:] = [ "  %s" % line for line in formatted[1:] ]
 	indented = "".join(formatted)
 	if indented.endswith('\n'):
 	    indented = indented[:-1]
-	self._log("ERROR", indented, ())
+	self._log(severity, indented, ())
+
+    def error_exc(self, (exclass, ex, tb), message=None, *args):
+	self.log_exc("ERROR", (exclass, ex, tb), message, *args)
+
+    def fatal_exc(self, (exclass, ex, tb), message=None, *args):
+	self.log_exc("FATAL", (exclass, ex, tb), message, *args)
 
 _THE_LOG = None
 def getLog():

Index: Queue.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/Queue.py,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- Queue.py	21 Aug 2002 19:09:48 -0000	1.13
+++ Queue.py	21 Aug 2002 20:49:16 -0000	1.14
@@ -345,8 +345,11 @@
 	if retriable:
 	    # Queue the new one before removing the old one, for 
 	    # crash-proofness
-	    retries,  addr, msg = self.getObject(handle)
-	    self.queueMessage(addr, msg, retries+1)
+	    retries, addr, msg = self.getObject(handle)
+	    # FFFF This test makes us never retry past the 10th attempt.
+	    # FFFF That's wrong; we should be smarter.
+	    if retries <= 10:
+		self.queueMessage(addr, msg, retries+1)
 	self.removeMessage(handle)    
 
 class TimedMixQueue(Queue):

Index: ServerMain.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/ServerMain.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- ServerMain.py	19 Aug 2002 15:33:56 -0000	1.4
+++ ServerMain.py	21 Aug 2002 20:49:17 -0000	1.5
@@ -5,10 +5,11 @@
 
    The main loop and related functionality for a Mixminion server
 
-   BUG: No support for encrypting private keys.n"""
+   BUG: No support for encrypting private keys."""
 
-import cPickle
 import os
+import getopt
+import sys
 
 import mixminion._minionlib
 import mixminion.Queue
@@ -208,7 +209,7 @@
 
 
 class MixminionServer:
-    def __init__(self, config, keyring):
+    def __init__(self, config):
 	self.config = config
 	self.keyring = ServerKeyring(config)
 	
@@ -263,6 +264,61 @@
 		self.moduleManager.cleanQueues()
 		nextShred = now + 6000
 
-	    # XXXX Remove long-undeliverable messages
+#----------------------------------------------------------------------
+
+def usageAndExit():
+    executable = sys.argv[0]
+    # XXXX show versioning info
+    print >>sys.stderr, "Usage: %s [-h] [-f configfile]" % cmd
+    sys.exit(0)
+
+def configFromArgs(cmd, args):
+    options, args = getopt.getopt(args, "hf=", ["help", "config="])
+    if args:
+	usageAndExit()
+    configFile = "/etc/miniond.conf"
+    for o,v in options:
+	if o in ('-h', '--help'):
+	    usageAndExit()
+	if o in ('-f', '--config'):
+	    configFile = v
+    try:
+	config = mixminion.Config.ServerConfig(fname=configFile)
+    except OSError:
+	print >>sys.stderr, "Error reading configuration file %r"%configFile
+	sys.exit(1)
+    except mixminion.Config.ConfigError, e:
+	print >>sys.stderr, "Error in configuration file %r"%configFile
+	print >>sys.stderr, str(e)
+	sys.exit(1)
+
+    return config
+
+def runServer(cmd, args):
+    config = configFromArgs(cmd, args)
+    try:
+	mixminion.Common.getLog().configure(config)
+	getLog().debug("Configuring server")
+	mixminion.Common.configureShredCommand(config)
+	mixminion.Crypto.init_crypto(config)
+	config.getModuleManager().configure(config)
+
+	server = MixminionServer(config)
+    except:
+	getLog().fatal_exc("Exception while configuring server")
+	print >>sys.stderr, "Shutting down because of exception"
+	sys.exit(1)
 
+    getLog().info("Starting server")
+    try:
+	server.run()
+    except KeyboardInterrupt:
+	pass
+    except:
+	getLog().fatal_exc("Exception while running server")
+    getLog().info("Server shutting down")
+    
+    sys.exit(0)
 
+if __name__ = '__main__':
+    runServer(sys.argv[0], sys.argv[1])