Index: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/collection/OAICollection.java
===================================================================
--- main/trunk/greenstone3/src/java/org/greenstone/gsdl3/collection/OAICollection.java	(revision 32827)
+++ main/trunk/greenstone3/src/java/org/greenstone/gsdl3/collection/OAICollection.java	(revision 32828)
@@ -114,4 +114,7 @@
 	}
 
+	// NOTE:
+	// Calling cleanUp() on OAIPMH object oai_service_rack will close any open dbs handles on module deactivation by MESSAGEROUTER (no deactivate yet called by OAIMESSAGEROUTER)
+	// But the OAIPMH object's cleanUp() is already called by superclass ServiceCluster, which goes around calling cleanUp() on all services/ServiceRacks.
 
 	/**
@@ -154,5 +157,7 @@
 	  message.appendChild(request);
 
-	  this.oai_service_rack = new OAIPMH();
+	  if(this.oai_service_rack == null) {
+		this.oai_service_rack = new OAIPMH();
+	  }
 	  this.oai_service_rack.setSiteHome(this.site_home);
 	  this.oai_service_rack.setSiteAddress(this.site_http_address);
Index: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/OAIPMH.java
===================================================================
--- main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/OAIPMH.java	(revision 32827)
+++ main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/OAIPMH.java	(revision 32828)
@@ -71,4 +71,7 @@
   protected HashMap<String, Element> format_meta_elem_map = null;
   
+  protected String index_stem = "";
+  protected String infodb_type = "";
+  
   /** constructor */
   public OAIPMH() {
@@ -78,10 +81,10 @@
   public void cleanUp() {
     super.cleanUp();//??
-    this.coll_db.closeDatabase();
+	this.coll_db.closeDatabase();
     if (this.oaiinf_db != null){
     	this.oaiinf_db.closeDatabase();
     }
-    
-  }
+  }
+  
   /** configure this service 
   info is the OAIPMH service rack from collectionConfig.xml, and 
@@ -103,6 +106,5 @@
     // the index stem is either specified in the buildConfig.xml file (extra_info) or uses the collection name
     Element metadata_list = (Element) GSXML.getChildByTagName(extra_info, GSXML.METADATA_ELEM+GSXML.LIST_MODIFIER);
-    String index_stem = "";
-    String infodb_type = "";
+
     if (metadata_list != null) {
       
@@ -110,10 +112,10 @@
       
       if (index_stem_elem != null) {
-	index_stem = GSXML.getNodeText(index_stem_elem);
+	this.index_stem = GSXML.getNodeText(index_stem_elem);
       }
 
       Element infodb_type_elem = (Element) GSXML.getNamedElement(metadata_list, GSXML.METADATA_ELEM, GSXML.NAME_ATT, "infodbType");
       if (infodb_type_elem != null) {
-	infodb_type = GSXML.getNodeText(infodb_type_elem);
+	this.infodb_type = GSXML.getNodeText(infodb_type_elem);
       }
 
@@ -121,40 +123,13 @@
 
     if (index_stem == null || index_stem.equals("")) {
-	index_stem = this.cluster_name; // index_stem is the name of the db in indext/text, it is <colname>.<db>
+	this.index_stem = this.cluster_name; // index_stem is the name of the db in indext/text, it is <colname>.<db>
     }
     if (infodb_type == null || infodb_type.equals("")) {
-      infodb_type = "gdbm"; // the default
-    }
-
-    coll_db = new SimpleCollectionDatabase(infodb_type);
-    if (!coll_db.databaseOK()) {
-      logger.error("Couldn't create the collection database of type "+infodb_type);
-      return false;
-    }
-
-    oaiinf_db = new SimpleCollectionDatabase(infodb_type);
-    if (!oaiinf_db.databaseOK()) {
-      logger.error("Couldn't create the oai-inf database of type "+infodb_type);
-      return false;
-    }
-
-    
-    // Open databases for querying
-    String coll_db_file = GSFile.collectionDatabaseFile(this.site_home, this.cluster_name, index_stem, infodb_type);
-    if (!this.coll_db.openDatabase(coll_db_file, SimpleCollectionDatabase.READ)) {
-      logger.error("Could not open collection database!");
-      return false;
-    }
-    // the oaiinf_db is called oai-inf.<infodb_type_extension>
-    String oaiinf_db_file = GSFile.OAIInfoDatabaseFile(this.site_home, this.cluster_name, "oai-inf", infodb_type);
-    File oaiinfFile = new File(oaiinf_db_file);
-    
-    if(!oaiinfFile.exists()) {
-	logger.warn("oai-inf database for collection + " + this.cluster_name + " does not exist.");
-	oaiinf_db = null;
-    } else if (!this.oaiinf_db.openDatabase(oaiinf_db_file, SimpleCollectionDatabase.READ)) {
-	logger.warn("Could not open oai-inf database for collection + " + this.cluster_name + "!");
-	oaiinf_db = null;
-    }
+      this.infodb_type = "gdbm"; // the default
+    }
+
+	// DB OPENING STUFF MOVED TO configureOAI(), because OAIPMH.configure() is called by the regular MessageRouter when this activates collections for the regular "library" servlet
+	// whereas OAIPMH.configureOAI() is only called by OAIMessageRouter when it activates collections for the "oaiserver" servlet (after OAIMessageRouter calls regular configure() first)
+	// We don't want the DBs opened twice: once by MessageRouter's call to OAIPMH.configure() and once by OAIMessageRouter calling OAIPMH.configure().
     
     // work out what sets this collection has. Will usually contain the collection itself, optional super collection, and maybe subcolls if appropriate classifiers are present.
@@ -235,5 +210,38 @@
       format_meta_elem_map.put(prefix, OAIXML.getMetadataPrefixElement(this.desc_doc, prefix, collection_version_format));
       
-    }
+    } // end for
+	
+	// Open the coll db and oai-inf db databases and store handles to them	
+    coll_db = new SimpleCollectionDatabase(infodb_type);
+    if (!coll_db.databaseOK()) {
+      logger.error("Couldn't create the collection database of type "+infodb_type);
+      return false;
+    }
+
+    oaiinf_db = new SimpleCollectionDatabase(infodb_type);
+    if (!oaiinf_db.databaseOK()) {
+      logger.error("Couldn't create the oai-inf database of type "+infodb_type);
+      return false;
+    }
+
+    
+    // Open databases for querying
+    String coll_db_file = GSFile.collectionDatabaseFile(this.site_home, this.cluster_name, index_stem, infodb_type);
+    if (!this.coll_db.openDatabase(coll_db_file, SimpleCollectionDatabase.READ)) {
+      logger.error("Could not open collection database!");
+      return false;
+    }
+    // the oaiinf_db is called oai-inf.<infodb_type_extension>
+    String oaiinf_db_file = GSFile.OAIInfoDatabaseFile(this.site_home, this.cluster_name, "oai-inf", infodb_type);
+    File oaiinfFile = new File(oaiinf_db_file);
+    
+    if(!oaiinfFile.exists()) {
+	logger.warn("oai-inf database for collection + " + this.cluster_name + " does not exist.");
+	oaiinf_db = null;
+    } else if (!this.oaiinf_db.openDatabase(oaiinf_db_file, SimpleCollectionDatabase.READ)) {
+	logger.warn("Could not open oai-inf database for collection + " + this.cluster_name + "!");
+	oaiinf_db = null;
+    }
+	
     return true;
   }
