[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[minion-cvs] Make server file locations more flexible [Bug 20]. Sti...
Update of /home/minion/cvsroot/src/minion/lib/mixminion/server
In directory moria.mit.edu:/tmp/cvs-serv28959/lib/mixminion/server
Modified Files:
EventStats.py Modules.py ServerConfig.py ServerKeys.py
ServerMain.py
Log Message:
Make server file locations more flexible [Bug 20]. Still needs more work.
Index: EventStats.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/server/EventStats.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- EventStats.py 25 Aug 2003 21:05:34 -0000 1.9
+++ EventStats.py 25 Nov 2003 02:15:14 -0000 1.10
@@ -304,11 +304,9 @@
global log
if config['Server']['LogStats']:
LOG.info("Enabling statistics logging")
- homedir = config['Server']['Homedir']
- statsfile = config['Server'].get('StatsFile')
- if not statsfile:
- statsfile = os.path.join(homedir, "stats")
- workfile = os.path.join(homedir, "work", "stats.tmp")
+ statsfile = config.getStatsFile()
+ workfile = os.path.join(config.getWorkDir(), "stats.tmp")
+ #XXXX006 ensure parent.
log = EventLog(
workfile, statsfile, config['Server']['StatsInterval'].getSeconds())
LOG.info("Statistics logging enabled")
Index: Modules.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/server/Modules.py,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -d -r1.62 -r1.63
--- Modules.py 24 Nov 2003 19:59:04 -0000 1.62
+++ Modules.py 25 Nov 2003 02:15:14 -0000 1.63
@@ -389,8 +389,7 @@
m.validateConfig(config, lines, contents)
def configure(self, config):
- self._setQueueRoot(os.path.join(config['Server']['Homedir'],
- 'work', 'queues', 'deliver'))
+ self._setQueueRoot(os.path.join(config.getQueueDir(), 'deliver'))
createPrivateDir(self.queueRoot)
for m in self.modules:
m.configure(config, self)
Index: ServerConfig.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/server/ServerConfig.py,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- ServerConfig.py 24 Nov 2003 19:59:05 -0000 1.41
+++ ServerConfig.py 25 Nov 2003 02:15:14 -0000 1.42
@@ -8,6 +8,7 @@
__all__ = [ "ServerConfig" ]
import operator
+import os
import mixminion.Config
import mixminion.server.Modules
@@ -183,6 +184,46 @@
mixInterval = self['Server']['MixInterval'].getSeconds()
_validateRetrySchedule(mixInterval, entry, sectionName)
+ def _get_fname(self, sec, ent, defaultRel):
+ """DOCDOC"""
+ raw = self[sec].get(ent)
+ homedir = self.getBaseDir()
+ if not raw:
+ return os.path.join(homedir, defaultRel)
+ if os.path.isabs(raw):
+ return raw
+ else:
+ return os.path.join(homedir, raw)
+
+ def getBaseDir(self):
+ """DOCDOC"""
+ v = self["Server"]["BaseDir"]
+ if v is None:
+ v = self["Server"]["Homedir"]
+ if v is None:
+ v = "/var/spool/minion"
+ return v
+ def getLogFile(self):
+ """DOCDOC"""
+ return self._get_fname("Server", "LogFile", "log")
+ def getStatsFile(self):
+ """DOCDOC"""
+ return self._get_fname("Server", "StatsFile", "stats")
+ def getKeyDir(self):
+ """DOCDOC"""
+ return self._get_fname("Server", "KeyDir", "keys")
+ def getWorkDir(self):
+ """DOCDOC"""
+ return self._get_fname("Server", "WorkDir", "work")
+ def getPidFile(self):
+ """DOCDOC"""
+ return self._get_fname("Server", "PidFile", "pid")
+ def getQueueDir(self):
+ """DOCDOC"""
+ if self["Server"]["QueueDir"] is None:
+ return os.path.join(self.getWorkDir(), 'queues')
+ else:
+ return self._get_fname("Server", "QueueDir", "work/queues")
def _validateRetrySchedule(mixInterval, schedule, sectionName):
"""Backend for ServerConfig.validateRetrySchedule -- separated for testing.
@@ -261,16 +302,24 @@
SERVER_SYNTAX = {
'Host' : mixminion.Config.ClientConfig._syntax['Host'],
'Server' : { '__SECTION__' : ('REQUIRE', None, None),
+ 'BaseDir' : ("ALLOW", "filename", None),
'Homedir' :
('ALLOW', "filename", "/var/spool/minion"),
- 'LogFile' : ('ALLOW', None, None),
+ # DOCDOC all these file options need documentation in
+ # DOCDOC the example mixminiond.conf.
+ 'LogFile' : ('ALLOW', "filename", None),
+ 'StatsFile' : ('ALLOW', "filename", None),
+ 'KeyDir' : ('ALLOW', "filename", None),
+ 'WorkDir' : ('ALLOW', "filename", None),
+ 'QueueDir' : ('ALLOW', "filename", None),
+ 'PidFile' : ('ALLOW', "filename", None),
+
'LogLevel' : ('ALLOW', "severity", "WARN"),
'EchoMessages' : ('ALLOW', "boolean", "no"),
'Daemon' : ('ALLOW', "boolean", "no"),
'LogStats' : ('ALLOW', "boolean", 'yes'),
'StatsInterval' : ('ALLOW', "interval",
"1 day"),
- 'StatsFile' : ('ALLOW', None, None),
'EncryptIdentityKey' :('ALLOW', "boolean", "no"),
'IdentityKeyBits': ('ALLOW', "int", "2048"),
'PublicKeyLifetime' : ('ALLOW', "interval",
Index: ServerKeys.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/server/ServerKeys.py,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -d -r1.58 -r1.59
--- ServerKeys.py 24 Nov 2003 19:59:05 -0000 1.58
+++ ServerKeys.py 25 Nov 2003 02:15:14 -0000 1.59
@@ -81,9 +81,11 @@
def configure(self, config):
"Set up a ServerKeyring from a config object"
self.config = config
- self.homeDir = config['Server']['Homedir']
- self.keyDir = os.path.join(self.homeDir, 'keys')
- self.hashDir = os.path.join(self.homeDir, 'work', 'hashlogs')
+ self.homeDir = config.getBaseDir()
+ self.keyDir = config.getKeyDir()
+ self.hashDir = os.path.join(config.getWorkDir(), 'hashlogs')
+ #DOCDOC
+ self.dhFile = os.path.join(config.getWorkDir(), 'tls', 'dhparam')
self.keyOverlap = config['Server']['PublicKeyOverlap'].getSeconds()
self.nextUpdate = None
self.currentKeys = None
@@ -269,10 +271,9 @@
LOG.warn("Removing identity key")
secureDelete([fn], blocking=1)
- dhfile = os.path.join(self.homeDir, 'work', 'tls', 'dhparam')
- if os.path.exists('dhfile'):
+ if os.path.exists(self.dhFile):
LOG.info("Removing diffie-helman parameters file")
- secureDelete([dhfile], blocking=1)
+ secureDelete([self.dhFile], blocking=1)
def createKeysAsNeeded(self,now=None):
"""Generate new keys and descriptors as needed, so that the next
@@ -440,20 +441,19 @@
def _getDHFile(self):
"""Return the filename for the diffie-helman parameters for the
server. Creates the file if it doesn't yet exist."""
- dhdir = os.path.join(self.homeDir, 'work', 'tls')
+ dhdir = os.path.split(self.dhFile)[0]
createPrivateDir(dhdir)
- dhfile = os.path.join(dhdir, 'dhparam')
- if not os.path.exists(dhfile):
+ if not os.path.exists(self.dhFile):
# ???? This is only using 512-bit Diffie-Hellman! That isn't
# ???? remotely enough.
LOG.info("Generating Diffie-Helman parameters for TLS...")
- mixminion._minionlib.generate_dh_parameters(dhfile, verbose=0)
+ mixminion._minionlib.generate_dh_parameters(self.dhFile, verbose=0)
LOG.info("...done")
else:
LOG.debug("Using existing Diffie-Helman parameter from %s",
- dhfile)
+ self.dhFile)
- return dhfile
+ return self.dhFile
def _getTLSContext(self, keys=None):
"""Create and return a TLS context from the currently live key."""
Index: ServerMain.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/server/ServerMain.py,v
retrieving revision 1.101
retrieving revision 1.102
diff -u -d -r1.101 -r1.102
--- ServerMain.py 19 Nov 2003 09:48:10 -0000 1.101
+++ ServerMain.py 25 Nov 2003 02:15:14 -0000 1.102
@@ -10,7 +10,7 @@
#XXXX make usage messages have the same format.
-## Directory layout:
+## Directory layout: DOCDOC this is now more complicated. :P
# MINION_HOME/work/queues/incoming/ [Queue of received,unprocessed pkts]
# mix/ [Mix pool]
# outgoing/ [Packets for mmtp delivery]
@@ -76,7 +76,7 @@
def getHomedirVersion(config):
"""Return the version of the server's homedir. If no version is found,
the version must be '1000'. """
- homeDir = config['Server']['Homedir']
+ homeDir = config.getBaseDir()
versionFile = os.path.join(homeDir, "version")
if not os.path.exists(homeDir):
return None
@@ -614,7 +614,8 @@
# processingThread: Thread to handle CPU-intensive activity without
# slowing down network interactivity.
# lockFile: An instance of Lockfile to prevent multiple servers from
- # running in the same directory
+ # running in the same directory. The filename for this lock is
+ # stored in self.pidFile.
# pidFile: Filename in which we store the pid of the running server.
def __init__(self, config):
"""Create a new server from a ServerConfig."""
@@ -622,7 +623,7 @@
LOG.debug("Initializing server")
self.config = config
- homeDir = config['Server']['Homedir']
+ homeDir = config.getBaseDir()
exists = getHomedirVersion(config)
@@ -632,16 +633,25 @@
writeFile(os.path.join(homeDir, "version"),
SERVER_HOMEDIR_VERSION, 0644)
- # Lock file.
- self.lockFile = Lockfile(os.path.join(homeDir, "lock"))
+ # Obsolete lock file.
+ #XXXX007: remove this check.
+ lockFname = os.path.join(homeDir, "lock")
+ if os.path.exists(lockFname):
+ lf = Lockfile(lockFname)
+ try:
+ lf.acquire()
+ lf.release()
+ except LockfileLocked:
+ raise UIError("Another (older) server seems to be running")
+
+ # The pid/lock file.
+ self.pidFile = config.getPidFile()
+ self.lockFile = Lockfile(self.pidFile)
try:
- self.lockFile.acquire()
+ self.lockFile.acquire(mode=0644)
except LockfileLocked:
raise UIError("Another server seems to be running.")
- # The pid file.
- self.pidFile = os.path.join(homeDir, "pid")
-
# Try to read the keyring. If we have a pre-0.0.4 version of
# mixminion, we might have some bad server descriptors lying
# around. If so, tell the user to run server-upgrade.
@@ -687,7 +697,7 @@
self.moduleManager = config.getModuleManager()
self.moduleManager.configure(config)
- queueDir = os.path.join(homeDir, 'work', 'queues')
+ queueDir = config.getQueueDir()
incomingDir = os.path.join(queueDir, "incoming")
LOG.debug("Initializing incoming queue")
@@ -778,7 +788,7 @@
def run(self):
"""Run the server; don't return unless we hit an exception."""
global GOT_HUP
- writeFile(self.pidFile, "%s\n"%os.getpid(), mode=0644)
+ self.lockFile.replaceContents("%s\n"%os.getpid())
self.cleanQueues()
@@ -925,10 +935,7 @@
EventStats.log.save()
- try:
- self.lockFile.release()
- finally:
- tryUnlink(self.pidFile)
+ self.lockFile.release()
#----------------------------------------------------------------------
def daemonize():
@@ -1150,9 +1157,9 @@
assert curVersion == "1000"
- homeDir = config['Server']['Homedir']
- keyDir = os.path.join(homeDir, 'keys')
- hashDir = os.path.join(homeDir, 'work', 'hashlogs')
+ homeDir = config.getBaseDir()
+ keyDir = config.getKeyDir()
+ hashDir = os.path.join(config.getWorkDir(), 'hashlogs')
keysets = []
if not os.path.exists(keyDir):
print >>sys.stderr, "No server keys to upgrade."
@@ -1180,10 +1187,10 @@
# Now we need to clean out all the old queues -- the messages in them
# are incompatible.
- queueDirs = [ os.path.join(homeDir, 'work', 'queues', 'incoming'),
- os.path.join(homeDir, 'work', 'queues', 'mix'),
- os.path.join(homeDir, 'work', 'queues', 'outgoing') ]
- deliver = os.path.join(homeDir, 'work', 'queues', 'deliver')
+ queueDirs = [ os.path.join(config.getQueueDir(), 'incoming'),
+ os.path.join(config.getQueueDir(), 'mix'),
+ os.path.join(config.getQueueDir(), 'outgoing') ]
+ deliver = os.path.join(config.getQueueDir(), 'deliver')
if os.path.exists(deliver):
for fn in os.listdir(deliver):
if os.path.isdir(os.path.join(deliver,fn)):
@@ -1225,9 +1232,9 @@
checkHomedirVersion(config)
- homeDir = config['Server']['Homedir']
- keyDir = os.path.join(homeDir, 'keys')
- hashDir = os.path.join(homeDir, 'work', 'hashlogs')
+ homeDir = config.getBaseDir()
+ keyDir = config.getKeyDir()
+ hashDir = os.path.join(config.getWorkDir(), 'hashlogs')
if not os.path.exists(keyDir):
print >>sys.stderr, "No server keys to delete"
else:
@@ -1292,8 +1299,8 @@
server if it's running. If 'reload', the signal is HUP. Else,
the signal is TERM.
"""
- homeDir = config['Server']['Homedir']
- pidFile = os.path.join(homeDir, "pid")
+ homeDir = config.getBaseDir()
+ pidFile = config.getPidFile()
if not os.path.exists(pidFile):
raise UIError("No server seems to be running.")
@@ -1336,7 +1343,7 @@
LOG.setMinSeverity("INFO")
mixminion.Crypto.init_crypto(config)
- keydir = os.path.join(config['Server']['Homedir'], 'keys')
+ keydir = config.getKeyDir()
items = os.listdir(keydir)
items.sort()
for fn in items: