Search in sources :

Example 1 with ShutdownHookProcessDestroyer

use of org.apache.commons.exec.ShutdownHookProcessDestroyer in project camel by apache.

the class DefaultExecCommandExecutor method prepareDefaultExecutor.

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;
}
Also used : ExecDefaultExecutor(org.apache.camel.component.exec.ExecDefaultExecutor) DefaultExecutor(org.apache.commons.exec.DefaultExecutor) ExecuteWatchdog(org.apache.commons.exec.ExecuteWatchdog) File(java.io.File) ExecDefaultExecutor(org.apache.camel.component.exec.ExecDefaultExecutor) ShutdownHookProcessDestroyer(org.apache.commons.exec.ShutdownHookProcessDestroyer)

Example 2 with ShutdownHookProcessDestroyer

use of org.apache.commons.exec.ShutdownHookProcessDestroyer in project frontend-maven-plugin by eirslett.

the class ProcessExecutor method createExecutor.

private Executor createExecutor(File workingDirectory, long timeoutInSeconds) {
    DefaultExecutor executor = new DefaultExecutor();
    executor.setWorkingDirectory(workingDirectory);
    // Fixes #41
    executor.setProcessDestroyer(new ShutdownHookProcessDestroyer());
    if (timeoutInSeconds > 0) {
        executor.setWatchdog(new ExecuteWatchdog(timeoutInSeconds * 1000));
    }
    return executor;
}
Also used : DefaultExecutor(org.apache.commons.exec.DefaultExecutor) ExecuteWatchdog(org.apache.commons.exec.ExecuteWatchdog) ShutdownHookProcessDestroyer(org.apache.commons.exec.ShutdownHookProcessDestroyer)

Example 3 with ShutdownHookProcessDestroyer

use of org.apache.commons.exec.ShutdownHookProcessDestroyer in project camel by apache.

the class ProvokeExceptionExecCommandExecutor method prepareDefaultExecutor.

@Override
protected DefaultExecutor prepareDefaultExecutor(ExecCommand execCommand) {
    DefaultExecutor executor = new DefaultExecutorMock();
    executor.setExitValues(null);
    executor.setProcessDestroyer(new ShutdownHookProcessDestroyer());
    return executor;
}
Also used : ExecDefaultExecutor(org.apache.camel.component.exec.ExecDefaultExecutor) DefaultExecutor(org.apache.commons.exec.DefaultExecutor) ShutdownHookProcessDestroyer(org.apache.commons.exec.ShutdownHookProcessDestroyer)

Example 4 with ShutdownHookProcessDestroyer

use of org.apache.commons.exec.ShutdownHookProcessDestroyer in project stanbol by apache.

the class JarExecutor method start.

/**
     * Start the jar if not done yet, and setup runtime hook to stop it.
     */
public void start() throws Exception {
    final ExecuteResultHandler h = new ExecuteResultHandler() {

        @Override
        public void onProcessFailed(ExecuteException ex) {
            log.error("Process execution failed:" + ex, ex);
        }

        @Override
        public void onProcessComplete(int result) {
            log.info("Process execution complete, exit code=" + result);
        }
    };
    final String vmOptions = System.getProperty("jar.executor.vm.options");
    final Executor e = new DefaultExecutor();
    if (this.workingDirectory != null) {
        e.setWorkingDirectory(this.workingDirectory);
    }
    final CommandLine cl = new CommandLine(javaExecutable);
    if (vmOptions != null && vmOptions.length() > 0) {
        // not the case for common usage patterns
        for (String option : StringUtils.split(vmOptions, " ")) {
            cl.addArgument(option);
        }
    }
    cl.addArgument("-jar");
    cl.addArgument(jarToExecute.getAbsolutePath());
    cl.addArgument("-p");
    cl.addArgument(String.valueOf(serverPort));
    log.info("Executing " + cl);
    e.setStreamHandler(new PumpStreamHandler());
    e.setProcessDestroyer(new ShutdownHookProcessDestroyer());
    e.execute(cl, h);
}
Also used : ExecuteResultHandler(org.apache.commons.exec.ExecuteResultHandler) CommandLine(org.apache.commons.exec.CommandLine) Executor(org.apache.commons.exec.Executor) DefaultExecutor(org.apache.commons.exec.DefaultExecutor) PumpStreamHandler(org.apache.commons.exec.PumpStreamHandler) DefaultExecutor(org.apache.commons.exec.DefaultExecutor) ExecuteException(org.apache.commons.exec.ExecuteException) ShutdownHookProcessDestroyer(org.apache.commons.exec.ShutdownHookProcessDestroyer)

Aggregations

DefaultExecutor (org.apache.commons.exec.DefaultExecutor)4 ShutdownHookProcessDestroyer (org.apache.commons.exec.ShutdownHookProcessDestroyer)4 ExecDefaultExecutor (org.apache.camel.component.exec.ExecDefaultExecutor)2 ExecuteWatchdog (org.apache.commons.exec.ExecuteWatchdog)2 File (java.io.File)1 CommandLine (org.apache.commons.exec.CommandLine)1 ExecuteException (org.apache.commons.exec.ExecuteException)1 ExecuteResultHandler (org.apache.commons.exec.ExecuteResultHandler)1 Executor (org.apache.commons.exec.Executor)1 PumpStreamHandler (org.apache.commons.exec.PumpStreamHandler)1