Changeset 24455

Show
Ignore:
Timestamp:
23.08.2011 20:28:57 (8 years ago)
Author:
ak19
Message:

Better way to ensure that the port is not arbitrarily modified. This bypasses the need to turn on the Do Not Modify Port server setting option by default, which then bypasses the need to make 8282 the default port for GS2 (which would have been necessary since the old GS2 default port of 80 would not have coped well with the Do Not Modify Port switch turned on by default).

Location:
main/trunk/greenstone3
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/resources/java/server.properties

    r24207 r24455  
    1717 
    1818ServerSettings.Title=Server settings 
    19 ServerSettings.Auto_Start=Enter the library automatically 
     19ServerSettings.Auto_Start=Enter the library automatically on startup 
    2020ServerSettings.Keep_Port=Do not modify port 
    2121ServerSettings.OK=OK 
  • main/trunk/greenstone3/src/java/org/greenstone/server/BaseServer.java

    r22085 r24455  
    6464     
    6565    config_properties = new Properties(); 
    66     reloadConfigProperties(); 
     66    reloadConfigProperties(true); // first time starting the server, work out port_number 
    6767 
    6868    dictionary = new Dictionary("server", lang, this.getClass().getClassLoader());   
     
    250250    } 
    251251     
    252     public  void reloadConfigProperties() { 
     252    public  void reloadConfigProperties(boolean port_has_changed) { 
    253253    try { 
    254254        FileInputStream in = new FileInputStream(config_properties_file); 
  • main/trunk/greenstone3/src/java/org/greenstone/server/BaseServerSettings.java

    r24233 r24455  
    234234        // save everything to config_properties if things have changed 
    235235        boolean has_changed = false; 
    236             boolean require_restart = false; 
     236        boolean require_restart = false; 
     237        boolean port_has_changed = false; 
    237238 
    238239        if (portNum != ((Integer)portNumber_spinner.getValue()).intValue()) { 
    239         has_changed = true; 
    240                 require_restart = true; 
     240            port_has_changed = true; 
     241            has_changed = true; 
     242            require_restart = true; 
    241243                server.reconfigRequired(); 
    242244                portNum = ((Integer)portNumber_spinner.getValue()).intValue(); 
     
    295297        scriptReadWrite.writeOutFile(BaseServer.config_properties_file, newFileLines); 
    296298 
    297         server.reloadConfigProperties(); 
     299        server.reloadConfigProperties(port_has_changed); 
    298300        server.reload(); // work out the URL again in case it has changed 
    299301        if (require_restart){ 
  • main/trunk/greenstone3/src/java/org/greenstone/server/Server2.java

    r24207 r24455  
    292292    } 
    293293 
    294     public void reloadConfigProperties() { 
    295     super.reloadConfigProperties(); 
     294    public void reloadConfigProperties(boolean port_has_changed) { 
     295    super.reloadConfigProperties(port_has_changed); 
    296296 
    297297    // make sure the port is okay, otherwise find another port 
    298298    // first choice is port 80, second choice starts at 8282 
    299299    String port = config_properties.getProperty("portnumber", "80"); 
    300     String keepport = config_properties.getProperty("keepport", "0"); // default is to not try to keep the same port 
     300    String keepport = config_properties.getProperty("keepport", "0"); // default is to not try to force the same port if in use by other servers 
    301301 
    302302    int portDefault = 8282; 
    303303    try { 
    304         int portNum = Integer.parseInt(port); 
    305         boolean verbose = true; 
    306         if(!PortFinder.isPortAvailable(portNum, verbose)) { // first time, print any Port Unavailable messages 
     304      int portNum = Integer.parseInt(port); 
     305      boolean verbose = true; 
     306      if(port_has_changed) { // this is the test that prevents the server from arbitrarily shifting the port.  
     307                            // only check at configured port if it's not the current port (the port we 
     308                            // are still running on), because that will always be in use and unavailable. 
     309        if(!PortFinder.isPortAvailable(portNum, verbose)) { // first time, print any Port Unavailable messages 
    307310        if(keepport.equals("1")) { 
    308311            String errorMsg = "Unable to run the Greenstone server on port " + port + ". It may already be in use."; 
     
    311314            System.err.println("If you wish to try another port, go to File > Settings of the Greenstone Server interface and either change the port number or untick the \"Do Not Modify Port\" option there. Then press the \"Enter Library\" button."); 
    312315            System.err.println("******************\n"); 
    313         } else { 
    314  
     316        } else { // can modify port, try to find a new port 
     317         
    315318            PortFinder portFinder = new PortFinder(portDefault, 101); 
    316319            // Search for a free port silently from now on--don't want more 
     
    336339            System.err.println("Running server on port " + port + "."); 
    337340        } 
    338         }     
     341        } 
     342      }  
    339343    } catch (Exception e) { 
    340344        recordError("Exception in Server2.reload(): " + e.getMessage());