@Override public Long call() throws Exception { Executor executor = new DefaultExecutor(); executor.setProcessDestroyer(new ShutdownHookProcessDestroyer()); ExecuteWatchdog watchDog = new ExecuteWatchdog(watchdogTimeout); executor.setWatchdog(watchDog); executor.setStreamHandler(new PumpStreamHandler(new MyLogOutputStream(handler, true), new MyLogOutputStream(handler, false))); Long exitValue; try { exitValue = new Long(executor.execute(commandline)); } catch (ExecuteException e) { exitValue = new Long(e.getExitValue()); } if (watchDog.killedProcess()) { exitValue = WATCHDOG_EXIST_VALUE; } return exitValue; }
@Test public void testKillEngineOnVmExit() throws Exception { StartTestEngineMojo mojo = rule.getMojo(); Executor startedProcess = null; try { startedProcess = mojo.startEngine(); assertThat(startedProcess.getProcessDestroyer()).isInstanceOf(ShutdownHookProcessDestroyer.class); ShutdownHookProcessDestroyer jvmShutdownHoock = (ShutdownHookProcessDestroyer) startedProcess.getProcessDestroyer(); assertThat(jvmShutdownHoock.size()) .as("One started engine process must be killed on VM end.") .isEqualTo(1); } finally { kill(startedProcess); } }
protected DefaultExecutor prepareDefaultExecutor(ExecCommand execCommand) { DefaultExecutor executor = new ExecDefaultExecutor(); executor.setExitValues(null); if (execCommand.getWorkingDir() != null) { executor.setWorkingDirectory(new File(execCommand.getWorkingDir()).getAbsoluteFile()); } if (execCommand.getTimeout() != ExecEndpoint.NO_TIMEOUT) { executor.setWatchdog(new ExecuteWatchdog(execCommand.getTimeout())); } executor.setProcessDestroyer(new ShutdownHookProcessDestroyer()); return executor; }
@Override protected DefaultExecutor prepareDefaultExecutor(ExecCommand execCommand) { DefaultExecutor executor = new DefaultExecutorMock(); executor.setExitValues(null); executor.setProcessDestroyer(new ShutdownHookProcessDestroyer()); return executor; }
public Executor start() throws Exception { CommandLine startCmd = toEngineCommand(Command.start); context.log.info("Start Axon.ivy Engine in folder: " + context.engineDirectory); Executor executor = createEngineExecutor(); executor.setStreamHandler(createEngineLogStreamForwarder(logLine -> findStartEngineUrl(logLine))); executor.setWatchdog(new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT)); executor.setProcessDestroyer(new ShutdownHookProcessDestroyer()); executor.execute(startCmd, asynchExecutionHandler()); waitForEngineStart(executor); return executor; }
private Executor createExecutor(File workingDirectory, long timeoutInSeconds) { DefaultExecutor executor = new DefaultExecutor(); executor.setWorkingDirectory(workingDirectory); executor.setProcessDestroyer(new ShutdownHookProcessDestroyer()); // Fixes #41 if (timeoutInSeconds > 0) { executor.setWatchdog(new ExecuteWatchdog(timeoutInSeconds * 1000)); } return executor; }
void run() throws Exception { if (propagateSystemProperties) { for (Entry<Object, Object> systemProp : System.getProperties().entrySet()) { String name = systemProp.getKey().toString(); String value = safeWindowsPath(systemProp.getValue().toString()); if (isPropagatableProperty(name)) { if (name.contains(" ")) { log.warn("System property name '" + name + "' contains a whitespace and can't be propagated"); } else if (MojoUtils.IS_WINDOWS && value.contains(" ")) { log.warn("System property value '" + value + "' contains a whitespace and can't be propagated on Windows"); } else { this.jvmArgs.add("-D" + name + "=" + safe(StringUtils.escape(value))); } } } } this.jvmArgs.add("-jar"); if (log.isDebugEnabled()) { log.debug(StringUtils.join(classpath.iterator(), ",\n")); } this.jvmArgs.add(MojoUtils.createBooterJar(classpath, MainWithArgsInFile.class.getName()).getCanonicalPath()); List<String> command = buildCommand(); Executor exec = new DefaultExecutor(); exec.setStreamHandler(new PumpStreamHandler(System.out, System.err, System.in)); exec.setProcessDestroyer(new ShutdownHookProcessDestroyer()); CommandLine cl = new CommandLine(javaExecutable); for (String arg : command) { cl.addArgument(arg, false); } if (log.isDebugEnabled()) { log.debug(cl.toString()); } int exitValue = exec.execute(cl); if (exitValue != 0) { throw new MojoFailureException("command line returned non-zero value:" + exitValue); } }