Ignore:
Timestamp:
2011-08-23T20:28:57+12:00 (13 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).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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());
Note: See TracChangeset for help on using the changeset viewer.