Index: main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java
===================================================================
--- main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java	(revision 32046)
+++ main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java	(revision 32049)
@@ -415,5 +415,9 @@
 					    if (GS3) { // issue the ant call to stop any running GS3
 						// (tomcat and networked Derby Server) by calling GS3ServerThread.stopServer()
-						GS3ServerThread.stopServer();
+						if(!GS3ServerThread.wasServerLaunchedOutsideGLI()) {
+						    GS3ServerThread.stopServer();
+						} else {
+						    System.err.println("@@@ Tomcat was launched outside GLI. Leaving it running...");
+						}
 					    } else { // issue the call to stop any running GS2 local library server
 						if (LocalLibraryServer.isRunning() == true) {
@@ -431,10 +435,11 @@
 				}
 				else { // local GS3, start the local tomcat
-				    
+
+				    if(!GS3ServerThread.wasServerLaunchedOutsideGLI()) {
+					System.err.println("@@@@ Launching tomcat from GLI");
 					GS3ServerThread thread = new GS3ServerThread(gsdl3_src_path, "restart");
 					thread.start();
-	
-
-
+				    }
+				    
 					// If fedora installed inside this local GS3, then ask for fedora login details now.
 					if (fedora_info.isActive()) { 
@@ -814,6 +819,10 @@
 		    //GS3ServerThread thread = new GS3ServerThread(Configuration.gsdl_path, "stop");
 		    //thread.start();
-
-		    GS3ServerThread.stopServer();
+		    if(!GS3ServerThread.wasServerLaunchedOutsideGLI()) {
+			System.err.println("@@@@ Off to call stopServer");
+			GS3ServerThread.stopServer();
+		    } else {
+			System.err.println("@@@ Tomcat was launched outside GLI. Leaving it running...");
+		    }
 		    
 		}
Index: main/trunk/gli/src/org/greenstone/gatherer/util/GS3ServerThread.java
===================================================================
--- main/trunk/gli/src/org/greenstone/gatherer/util/GS3ServerThread.java	(revision 32046)
+++ main/trunk/gli/src/org/greenstone/gatherer/util/GS3ServerThread.java	(revision 32049)
@@ -48,9 +48,18 @@
     String _gsdl3_src_path = "";
     String _ant_command = "";
+
+    // isIndependentServer is true/1 if tomcat was already running when GLI was started up
+    // in which case GLI doesn't need to ask tomcat to be run, nor does it need to stop the server on exit
+    // Value can be -1, 0 or 1. -1 means not yet determined. 0 is false, 1 is true
+    static private final boolean isIndependentServer = GS3ServerThread.isServerRunning();
+
+    /*static {
+	isIndependentServer = isServerRunning();
+	}*/
     
     public GS3ServerThread(String gsdl3_src_path, String ant_command)
     {
 	_gsdl3_src_path = gsdl3_src_path;
-	_ant_command = ant_command; // "restart"
+	_ant_command = ant_command; // "restart"	
     }
     
@@ -145,3 +154,33 @@
 	
     }
+
+    public static boolean isServerRunning() {
+	String antCmd = "ant verbose-check-tomcat-running";
+	
+	SafeProcess p = null;
+	if (Utility.isWindows()) {
+	    // cmd /C "cd "C:\path\to\greenstone3" && ant stop"
+	    p = new SafeProcess("cmd /C \"cd \"" + Configuration.gsdl3_src_path + File.separator + "\" && "+antCmd+"\"");	
+	} else {
+	    p = new SafeProcess(new String[]{"/bin/bash", "-c", antCmd+" -f \"" + Configuration.gsdl3_src_path + File.separator + "build.xml\""});
+	}
+	
+	System.err.println("**** Checking if tomcat is running");
+	p.runProcess();
+	String output = p.getStdOutput();
+
+	if(output.contains("Tomcat is running: true")) {
+	    System.err.println("**** Tomcat was running");
+	    return true;
+	}
+	
+	System.err.println("**** Tomcat was not running");
+	return false;
+    }
+    
+    // first time, call this on startup, before running GS3ServerThread
+    public static boolean wasServerLaunchedOutsideGLI() {
+	System.err.println("@@@ Was server launched outside GLI: " + isIndependentServer);
+	return isIndependentServer;
+    }
 }
Index: main/trunk/greenstone3/build.xml
===================================================================
--- main/trunk/greenstone3/build.xml	(revision 32046)
+++ main/trunk/greenstone3/build.xml	(revision 32049)
@@ -1724,4 +1724,22 @@
     </condition>
   </target>
+  
+  <!--
+      <target name="verbose-check-tomcat-running">
+      <condition property="tomcat.isrunning" value="true" else="false">
+      <http url="${server.protocol}://${tomcat.server}:${tomcat.port}"/>
+      </condition>
+      <echo>Tomcat is running: ${tomcat.isrunning}</echo>
+      </target>
+  -->
+  <target name="verbose-check-tomcat-running" depends="check-tomcat-running">   
+    <if>
+      <bool>
+	<istrue value="${tomcat.isrunning}"/>
+      </bool>      
+      <echo>Tomcat is running: ${tomcat.isrunning}</echo>
+      <else><echo>Tomcat is running: false</echo></else><!-- tomcat.isrunning not set -->
+    </if>
+  </target>  
   
   <!-- Need a copy of the check-tomcat-running target with a distinct property, because ant restart runs 
