- Timestamp:
- 2011-06-28T17:07:42+12:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/src/java/org/greenstone/server/Server2.java
r23251 r24207 26 26 import org.greenstone.server.BaseServer; 27 27 import org.greenstone.server.BaseProperty; 28 28 29 29 30 public class Server2 extends BaseServer … … 287 288 suffix = httpprefix + suffix; 288 289 } 289 290 290 291 libraryURL = "http://" + host + ":" + port + suffix; 291 292 } … … 297 298 // first choice is port 80, second choice starts at 8282 298 299 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 301 299 302 int portDefault = 8282; 300 303 try { … … 302 305 boolean verbose = true; 303 306 if(!PortFinder.isPortAvailable(portNum, verbose)) { // first time, print any Port Unavailable messages 304 305 PortFinder portFinder = new PortFinder(portDefault, 101); 306 // Search for a free port silently from now on--don't want more 307 // messages saying that a port could not be found... 308 portNum = portFinder.findPortInRange(!verbose); 309 310 if (portNum == -1) { 311 // If we've still not found a free port, do we try the default port again? 312 System.err.println("No free port found. Going to try on " + portDefault + " anyway."); 313 port = Integer.toString(portDefault); 307 if(keepport.equals("1")) { 308 String errorMsg = "Unable to run the Greenstone server on port " + port + ". It may already be in use."; 309 System.err.println("\n******************"); 310 logger_.error(errorMsg); 311 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."); 312 System.err.println("******************\n"); 314 313 } else { 315 port = Integer.toString(portNum); 316 } 317 config_properties.setProperty("portnumber", port); // store the correct port 318 319 // write this updated port to the config file, since the configure target uses the file to run 320 ScriptReadWrite scriptReadWrite = new ScriptReadWrite(); 321 ArrayList fileLines = scriptReadWrite.readInFile(BaseServer.config_properties_file); 322 scriptReadWrite.replaceOrAddLine(fileLines, "portnumber", port, false); // write the correct port 323 scriptReadWrite.writeOutFile(config_properties_file, fileLines); 324 325 configure_required_ = true; 326 System.err.println("Running server on port " + port + "."); 314 315 PortFinder portFinder = new PortFinder(portDefault, 101); 316 // Search for a free port silently from now on--don't want more 317 // messages saying that a port could not be found... 318 portNum = portFinder.findPortInRange(!verbose); 319 320 if (portNum == -1) { 321 // If we've still not found a free port, do we try the default port again? 322 System.err.println("No free port found. Going to try on " + portDefault + " anyway."); 323 port = Integer.toString(portDefault); 324 } else { 325 port = Integer.toString(portNum); 326 } 327 config_properties.setProperty("portnumber", port); // store the correct port 328 329 // write this updated port to the config file, since the configure target uses the file to run 330 ScriptReadWrite scriptReadWrite = new ScriptReadWrite(); 331 ArrayList fileLines = scriptReadWrite.readInFile(BaseServer.config_properties_file); 332 scriptReadWrite.replaceOrAddLine(fileLines, "portnumber", port, false); // write the correct port 333 scriptReadWrite.writeOutFile(config_properties_file, fileLines); 334 335 configure_required_ = true; 336 System.err.println("Running server on port " + port + "."); 337 } 327 338 } 328 339 } catch (Exception e) {
Note:
See TracChangeset
for help on using the changeset viewer.