Changeset 32049 for main/trunk/gli

Show
Ignore:
Timestamp:
20.10.2017 15:50:51 (2 years ago)
Author:
ak19
Message:

User on mailing list found it frustrating that GLI stops the GS3 Server on exit. Gli tends to launch and stop the GS3 server on GLI start and quit. Now it first checks if the server was already running on startup (launched externally) and only launches and stops the GS3 server if a server had not been launched external to GLI on GLI startup.

Location:
main/trunk/gli/src/org/greenstone/gatherer
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/gli/src/org/greenstone/gatherer/Gatherer.java

    r31884 r32049  
    415415                        if (GS3) { // issue the ant call to stop any running GS3 
    416416                        // (tomcat and networked Derby Server) by calling GS3ServerThread.stopServer() 
    417                         GS3ServerThread.stopServer(); 
     417                        if(!GS3ServerThread.wasServerLaunchedOutsideGLI()) { 
     418                            GS3ServerThread.stopServer(); 
     419                        } else { 
     420                            System.err.println("@@@ Tomcat was launched outside GLI. Leaving it running..."); 
     421                        } 
    418422                        } else { // issue the call to stop any running GS2 local library server 
    419423                        if (LocalLibraryServer.isRunning() == true) { 
     
    431435                } 
    432436                else { // local GS3, start the local tomcat 
    433                      
     437 
     438                    if(!GS3ServerThread.wasServerLaunchedOutsideGLI()) { 
     439                    System.err.println("@@@@ Launching tomcat from GLI"); 
    434440                    GS3ServerThread thread = new GS3ServerThread(gsdl3_src_path, "restart"); 
    435441                    thread.start(); 
    436      
    437  
    438  
     442                    } 
     443                     
    439444                    // If fedora installed inside this local GS3, then ask for fedora login details now. 
    440445                    if (fedora_info.isActive()) {  
     
    814819            //GS3ServerThread thread = new GS3ServerThread(Configuration.gsdl_path, "stop"); 
    815820            //thread.start(); 
    816  
    817             GS3ServerThread.stopServer(); 
     821            if(!GS3ServerThread.wasServerLaunchedOutsideGLI()) { 
     822            System.err.println("@@@@ Off to call stopServer"); 
     823            GS3ServerThread.stopServer(); 
     824            } else { 
     825            System.err.println("@@@ Tomcat was launched outside GLI. Leaving it running..."); 
     826            } 
    818827             
    819828        } 
  • main/trunk/gli/src/org/greenstone/gatherer/util/GS3ServerThread.java

    r31593 r32049  
    4848    String _gsdl3_src_path = ""; 
    4949    String _ant_command = ""; 
     50 
     51    // isIndependentServer is true/1 if tomcat was already running when GLI was started up 
     52    // in which case GLI doesn't need to ask tomcat to be run, nor does it need to stop the server on exit 
     53    // Value can be -1, 0 or 1. -1 means not yet determined. 0 is false, 1 is true 
     54    static private final boolean isIndependentServer = GS3ServerThread.isServerRunning(); 
     55 
     56    /*static { 
     57    isIndependentServer = isServerRunning(); 
     58    }*/ 
    5059     
    5160    public GS3ServerThread(String gsdl3_src_path, String ant_command) 
    5261    { 
    5362    _gsdl3_src_path = gsdl3_src_path; 
    54     _ant_command = ant_command; // "restart" 
     63    _ant_command = ant_command; // "restart"     
    5564    } 
    5665     
     
    145154     
    146155    } 
     156 
     157    public static boolean isServerRunning() { 
     158    String antCmd = "ant verbose-check-tomcat-running"; 
     159     
     160    SafeProcess p = null; 
     161    if (Utility.isWindows()) { 
     162        // cmd /C "cd "C:\path\to\greenstone3" && ant stop" 
     163        p = new SafeProcess("cmd /C \"cd \"" + Configuration.gsdl3_src_path + File.separator + "\" && "+antCmd+"\"");    
     164    } else { 
     165        p = new SafeProcess(new String[]{"/bin/bash", "-c", antCmd+" -f \"" + Configuration.gsdl3_src_path + File.separator + "build.xml\""}); 
     166    } 
     167     
     168    System.err.println("**** Checking if tomcat is running"); 
     169    p.runProcess(); 
     170    String output = p.getStdOutput(); 
     171 
     172    if(output.contains("Tomcat is running: true")) { 
     173        System.err.println("**** Tomcat was running"); 
     174        return true; 
     175    } 
     176     
     177    System.err.println("**** Tomcat was not running"); 
     178    return false; 
     179    } 
     180     
     181    // first time, call this on startup, before running GS3ServerThread 
     182    public static boolean wasServerLaunchedOutsideGLI() { 
     183    System.err.println("@@@ Was server launched outside GLI: " + isIndependentServer); 
     184    return isIndependentServer; 
     185    } 
    147186}