@Override public void startNow() throws IOException{ this.process = startProcess(); Runtime.getRuntime().addShutdownHook(shutdownHook); logWatcher = new JenkinsLogWatcher(getLogId(),process,logFile); logWatcher.start(); try { LOGGER.info("Waiting for Jenkins to become running in "+ this); this.logWatcher.waitTillReady(); LOGGER.info("Jenkins is running in " + this); } catch (Exception e) { diagnoseFailedLoad(e); } }
public String runCommand(String com) { StringBuffer output = new StringBuffer(); Process p; String line = ""; try { p = Runtime.getRuntime().exec(com); p.waitFor(); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); while ((reader.readLine()) != null) { output.append(line = reader.readLine() + "\n"); } } catch (Exception e) { e.printStackTrace(); } return output.toString(); }
/** * Checks if address can be reached using one argument InetAddress.isReachable() version or ping * command if failed. * * @param addr Address to check. * @param reachTimeout Timeout for the check. * @return {@code True} if address is reachable. */ public static boolean reachableByPing(InetAddress addr, int reachTimeout) { try { if (addr.isReachable(reachTimeout)) return true; String cmd = String.format("ping -%s 1 %s", U.isWindows() ? "n" : "c", addr.getHostAddress()); Process myProc = Runtime.getRuntime().exec(cmd); myProc.waitFor(); return myProc.exitValue() == 0; } catch (IOException ignore) { return false; } catch (InterruptedException ignored) { Thread.currentThread().interrupt(); return false; } }
@Override public void stopNow() throws IOException{ process.getProcess().destroy(); Runtime.getRuntime().removeShutdownHook(shutdownHook); }