void run(Process p, IRuntimeConfig runtimeConfig, long timeoutNanos) throws IOException { CollectingAndForwardingStreamProcessor wrapped = new CollectingAndForwardingStreamProcessor(runtimeConfig.getProcessOutput().getOutput()); IStreamProcessor loggingWatch = StreamToLineProcessor.wrap(wrapped); try { ReaderProcessor processorOne = Processors.connect(new InputStreamReader(p.getInputStream()), loggingWatch); ReaderProcessor processorTwo = Processors.connect(new InputStreamReader(p.getErrorStream()), loggingWatch); int retCode = tope.waitFor(p, timeoutNanos); if (retCode != 0) { processorOne.join(10000); processorTwo.join(10000); resolveException(retCode, wrapped.getOutput()); } } catch (InterruptedException e) { throw new RuntimeException(e); } }
protected void onAfterProcessStart(ProcessControl process, RuntimeConfig runtimeConfig) { ProcessOutput outputConfig = runtimeConfig.getProcessOutput(); Processors.connect(process.getReader(), outputConfig.getOutput()); Processors.connect(process.getError(), StreamToLineProcessor.wrap(outputConfig.getError())); }
protected void onAfterProcessStart(ProcessControl process, IRuntimeConfig runtimeConfig) throws IOException { ProcessOutput outputConfig = runtimeConfig.getProcessOutput(); Processors.connect(process.getReader(), outputConfig.getOutput()); Processors.connect(process.getError(), StreamToLineProcessor.wrap(outputConfig.getError())); }
public static boolean isProcessRunning(Platform platform, long pid) { try { final Process pidof; if (platform.isUnixLike()) { pidof = Runtime.getRuntime().exec( new String[] { "kill", "-0", "" + pid }); return pidof.waitFor() == 0; } else { // windows // process might be in either NOT RESPONDING due to // firewall blocking, or could be RUNNING final String[] cmd = { "tasklist.exe", "/FI", "PID eq " + pid ,"/FO", "CSV" }; logger.trace("Command: {}", Arrays.asList(cmd)); ProcessBuilder processBuilder = ProcessControl .newProcessBuilder(Arrays.asList(cmd), true); Process process = processBuilder.start(); // look for the PID in the output, pass it in for 'success' state LogWatchStreamProcessor logWatch = new LogWatchStreamProcessor(""+pid, new HashSet<String>(), StreamToLineProcessor.wrap(Processors.silent())); Processors.connect(new InputStreamReader(process.getInputStream()), logWatch); logWatch.waitForResult(2000); logger.trace("logWatch output: {}", logWatch.getOutput()); return logWatch.isInitWithSuccess(); } } catch (IOException | InterruptedException e) { logger.error("Trying to get process status", e); } return false; }
Processors.connect(new InputStreamReader(process.getInputStream()), logWatch); logWatch.waitForResult(2000); logger.trace("logWatch output: {}", logWatch.getOutput());
public static boolean executeCommandLine(ISupportConfig support, String label, ProcessConfig processConfig) { boolean ret = false; List<String> commandLine = processConfig.getCommandLine(); try { ProcessControl process = fromCommandLine(support, processConfig.getCommandLine(), processConfig.getError() == null); Processors.connect(process.getReader(), processConfig.getOutput()); Thread.sleep(SLEEPT_TIMEOUT); ret = process.stop() == 0; logger.info("execSuccess: {} {}", ret, commandLine); return ret; } catch (IOException e) { logger.error("" + commandLine, e); } catch (InterruptedException e) { logger.error("" + commandLine, e); } return false; }
public static boolean executeCommandLine(SupportConfig support, String label, ProcessConfig processConfig) { boolean ret; List<String> commandLine = processConfig.getCommandLine(); try { ProcessControl process = fromCommandLine(support, processConfig.getCommandLine(), processConfig.getError() == null); Processors.connect(process.getReader(), processConfig.getOutput()); Thread.sleep(SLEEP_TIMEOUT); ret = process.stop() == 0; logger.info("execSuccess: {} {}", ret, commandLine); return ret; } catch (IOException | InterruptedException e) { logger.error("" + commandLine, e); } return false; }
@Override protected void onAfterProcessStart(ProcessControl process, IRuntimeConfig runtimeConfig) throws IOException { final ProcessOutput outputConfig = runtimeConfig.getProcessOutput(); final LogWatchStreamProcessor logWatch = new LogWatchStreamProcessor( "performing post-bootstrap initialization", singleton("[initdb error]"), StreamToLineProcessor.wrap(outputConfig.getOutput())); Processors.connect(process.getReader(), logWatch); Processors.connect(process.getError(), StreamToLineProcessor.wrap(outputConfig.getError())); logWatch.waitForResult(getConfig().timeout().startupTimeout()); } }
@Override public void onAfterProcessStart(final ProcessControl process, final IRuntimeConfig runtimeConfig) throws IOException { outputWatch = new NotifyingStreamProcessor(StreamToLineProcessor.wrap(runtimeConfig.getProcessOutput().getOutput())); Processors.connect(process.getReader(), outputWatch); Processors.connect(process.getError(), outputWatch); ResultMatchingListener startupListener = outputWatch.addListener(new ResultMatchingListener("ready for connections")); try { startupListener.waitForResult(getConfig().getTimeout(MILLISECONDS)); if (!startupListener.isInitWithSuccess()) { throw new RuntimeException("mysql start failed with error: " + startupListener.getFailureFound()); } } catch (Exception e) { // emit IO exception for {@link AbstractProcess} would try to stop running process gracefully throw new IOException(e); } }
@Override protected final void onAfterProcessStart(ProcessControl process, IRuntimeConfig runtimeConfig) throws IOException { ProcessOutput outputConfig = runtimeConfig.getProcessOutput(); LogWatchStreamProcessor logWatch = new LogWatchStreamProcessor(successMessage(), knownFailureMessages(), StreamToLineProcessor.wrap(outputConfig.getOutput())); Processors.connect(process.getReader(), logWatch); Processors.connect(process.getError(), StreamToLineProcessor.wrap(outputConfig.getError())); logWatch.waitForResult(getConfig().timeout().getStartupTimeout()); if (logWatch.isInitWithSuccess()) { setProcessId(Mongod.getMongodProcessId(logWatch.getOutput(), -1)); } else { String failureFound = logWatch.getFailureFound(); if (failureFound==null) { failureFound="\n" + "----------------------\n" + "Hmm.. no failure message.. \n" + "...the cause must be somewhere in the process output\n" + "----------------------\n" + ""+logWatch.getOutput(); } try { // Process could be finished with success here! In this case no need to throw an exception! if(process.waitFor() != 0){ throw new IOException("Could not start process: "+failureFound); } } catch (InterruptedException e) { throw new IOException("Could not start process: "+failureFound, e); } } }
@Override protected final void onAfterProcessStart(ProcessControl process, IRuntimeConfig runtimeConfig) throws IOException { ProcessOutput outputConfig = runtimeConfig.getProcessOutput(); // memcached prints all status messages on error console, and only // if // started with -vv LogWatchStreamProcessor logWatch = new LogWatchStreamProcessor( "server listening", knownFailureMessages(), StreamToLineProcessor.wrap(outputConfig.getError())); Processors.connect(process.getError(), logWatch); logWatch.waitForResult(getConfig().timeout().getStartupTimeout()); if (!logWatch.isInitWithSuccess()) { throw new IOException("Could not start process:" + logWatch.getOutput()); } if (Distribution.detectFor(getConfig().version()).getPlatform() == Platform.Windows) { // On windows, process won't be writing a pid file. Sigh. Use // some // force to find out the pid anyways. This works pretty well // on Unix // (won't help us much here..) and needs Sigar lib on Windows. setProcessId(process.getPid()); } else { setProcessId(getPidFromFile(pidFile())); } }