- Timestamp:
- 2017-04-06T20:35:36+12:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/gli/src/org/greenstone/gatherer/util/GS3ServerThread.java
r31583 r31584 55 55 } 56 56 57 public void old_run()58 {59 try60 {61 ///System.err.println("**** GS3 server : " + _ant_command);62 63 String shellCommand = null;64 Process p = null;65 if (Utility.isWindows())66 {67 if(_ant_command.indexOf("start") != -1) { // running an "ant (re)start" command on windows, run start68 _ant_command = "start";69 }70 // The path in quotes, and the entire sequence of commands in quotes as well71 // E.g. the following works: cmd /C "cd "C:\path\to\greenstone3" && ant stop"72 // and it preserves any spaces in the path to GSDL3SRCHOME (_gsdl3_src_path).73 p = Runtime.getRuntime().exec("cmd /C \"cd \"" + _gsdl3_src_path + File.separator + "\" && ant " + _ant_command + "\"");74 }75 else76 {77 if(_ant_command.indexOf("start") != -1) { // if running an "ant (re)start" command on non-Windows, run restart78 _ant_command = "restart";79 }80 p = Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", "ant " + _ant_command + " -f \"" + _gsdl3_src_path + File.separator + "build.xml\""});81 }82 83 if (p != null) {84 // in order for the process.waitFor() method to work with Java 6 (JRE 6 is included in GS binaries)85 // need to make sure the IOstreams of the process are not blocked. For Java 7, this is not necessary86 // and a waitFor() is sufficient. But with Java 6, the waitFor() causes the server to finally start87 // after the user has quit GLI.88 89 // Process takes no input, but we will still catch this iostream too90 // And we'll catch the error and output streams to prevent them from blocking during waitFor()91 // (For normal input and output stream handling using the Gobblers, see FormatConversionDialog.java)92 SafeProcess.OutputStreamGobbler inputGobbler93 = new SafeProcess.OutputStreamGobbler(p.getOutputStream());94 SafeProcess.InputStreamGobbler errorGobbler95 = new SafeProcess.InputStreamGobbler(p.getErrorStream(), true);96 SafeProcess.InputStreamGobbler outputGobbler97 = new SafeProcess.InputStreamGobbler(p.getInputStream());98 99 errorGobbler.start();100 outputGobbler.start();101 inputGobbler.start();102 103 // the important part: wait for the process (ant stop or start or re-start to terminate)104 int result = p.waitFor();105 if(result != 0) {106 System.err.println("**** Failed to successfully " + _ant_command + " the GS3 server.");107 }108 109 outputGobbler.join();110 errorGobbler.join();111 inputGobbler.join();112 } else {113 System.err.println("**** Could not start the Process to " + _ant_command + " the GS3 server.");114 }115 116 }117 catch(Exception ex)118 {119 ex.printStackTrace();120 }121 }122 57 123 58 public void run() … … 172 107 } 173 108 174 public static void old_stopServer() {175 176 System.err.println("Stopping GS3 Server");177 try {178 String shellCommand = null;179 Process p = null;180 if (Utility.isWindows()) {181 // cmd /C "cd "C:\path\to\greenstone3" && ant stop"182 p = Runtime.getRuntime().exec("cmd /C \"cd \"" + Configuration.gsdl3_src_path + File.separator + "\" && ant stop\"");183 } else {184 p = Runtime.getRuntime().exec(new String[]{"/bin/bash", "-c", "ant stop -f \"" + Configuration.gsdl3_src_path + File.separator + "build.xml\""});185 }186 // doing a p.waitFor() without processing the Process' IOstreams causes blocking with Java 6187 // (i.e. when JRE 6 included with GS binaries). However, p.waitFor() with Java 7 is fine.188 /*if(p != null && p.waitFor() == 0) {189 DebugStream.println("********** SUCCESSFULLY stopped THE GS3 SERVER ON EXIT");190 }191 else {192 System.err.println("********** FAILED TO SUCCESSFULLY stop THE GS3 SERVER ON EXIT");193 //throw new Exception ("Failed to successfully stop the GS3 server on exit.");194 }*/195 } catch(Exception e) {196 System.err.println("Exception when trying to stop the tomcat web server: " + e);197 DebugStream.printStackTrace(e);198 }199 }200 109 201 110 // can't call ant stop from its own thread - what if GLI has exited by then?
Note:
See TracChangeset
for help on using the changeset viewer.