use of org.apache.commons.exec.DefaultExecutor in project zeppelin by apache.
the class ShellInterpreter method createSecureConfiguration.
public void createSecureConfiguration() throws InterpreterException {
Properties properties = getProperties();
CommandLine cmdLine = CommandLine.parse(shell);
cmdLine.addArgument("-c", false);
String kinitCommand = String.format("kinit -k -t %s %s", properties.getProperty("zeppelin.shell.keytab.location"), properties.getProperty("zeppelin.shell.principal"));
cmdLine.addArgument(kinitCommand, false);
DefaultExecutor executor = new DefaultExecutor();
try {
executor.execute(cmdLine);
} catch (Exception e) {
LOGGER.error("Unable to run kinit for zeppelin user " + kinitCommand, e);
throw new InterpreterException(e);
}
}
use of org.apache.commons.exec.DefaultExecutor in project zeppelin by apache.
the class ShellInterpreter method internalInterpret.
@Override
public InterpreterResult internalInterpret(String cmd, InterpreterContext context) {
LOGGER.debug("Run shell command '{}'", cmd);
CommandLine cmdLine = CommandLine.parse(shell);
// they need to be delimited by '&&' instead
if (isWindows) {
String[] lines = StringUtils.split(cmd, "\n");
cmd = StringUtils.join(lines, " && ");
}
cmdLine.addArgument(cmd, false);
try {
contextMap.put(context.getParagraphId(), context);
DefaultExecutor executor = new DefaultExecutor();
executor.setStreamHandler(new PumpStreamHandler(context.out, context.out));
executor.setWatchdog(new ExecuteWatchdog(Long.MAX_VALUE));
executorMap.put(context.getParagraphId(), executor);
if (Boolean.valueOf(getProperty(DIRECTORY_USER_HOME))) {
executor.setWorkingDirectory(new File(System.getProperty("user.home")));
}
int exitVal = executor.execute(cmdLine);
LOGGER.info("Paragraph {} return with exit value: {}", context.getParagraphId(), exitVal);
if (exitVal == 0) {
return new InterpreterResult(Code.SUCCESS);
} else {
return new InterpreterResult(Code.ERROR);
}
} catch (ExecuteException e) {
int exitValue = e.getExitValue();
LOGGER.error("Can not run command: " + cmd, e);
Code code = Code.ERROR;
StringBuilder messageBuilder = new StringBuilder();
if (exitValue == 143) {
code = Code.INCOMPLETE;
messageBuilder.append("Paragraph received a SIGTERM\n");
LOGGER.info("The paragraph {} stopped executing: {}", context.getParagraphId(), messageBuilder.toString());
}
messageBuilder.append("ExitValue: " + exitValue);
return new InterpreterResult(code, messageBuilder.toString());
} catch (IOException e) {
LOGGER.error("Can not run command: " + cmd, e);
return new InterpreterResult(Code.ERROR, e.getMessage());
} finally {
executorMap.remove(context.getParagraphId());
contextMap.remove(context.getParagraphId());
}
}
use of org.apache.commons.exec.DefaultExecutor in project tycho by eclipse.
the class JdkLibraryInfoProvider method generateLibraryInfo.
private LibraryInfo generateLibraryInfo(String javaHome) {
String executable = javaHome + File.separator + "bin" + File.separator + "java";
if (File.separatorChar == '\\') {
executable = executable + ".exe";
}
if (!new File(executable).isFile()) {
getLog().warn(executable + " not found. Fallback to scan " + javaHome + "/lib/*.jar and " + javaHome + "/lib/ext/*.jar for bootclasspath");
return new LibraryInfo("unknown", scanLibFolders(javaHome), new String[0], new String[0]);
}
CommandLine cli = new CommandLine(executable);
cli.addArguments(new String[] { "-classpath", getLibDetectorJar().getAbsolutePath(), "org.eclipse.tycho.libdetector.LibraryDetector" }, false);
DefaultExecutor executor = new DefaultExecutor();
ExecuteWatchdog watchdog = new ExecuteWatchdog(30 * 1000L);
executor.setWatchdog(watchdog);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
PumpStreamHandler handler = new PumpStreamHandler(outputStream);
executor.setStreamHandler(handler);
int exitValue = -1;
try {
exitValue = executor.execute(cli);
} catch (ExecuteException e) {
if (watchdog.killedProcess()) {
throw new RuntimeException("Timeout 30 s exceeded. Commandline " + cli.toString() + " was killed. Output: " + outputStream.toString());
}
} catch (IOException e) {
throw new RuntimeException(e);
}
if (exitValue == 0) {
return parseLibraryInfo(outputStream.toString(), javaHome);
} else {
throw new RuntimeException(cli.toString() + " process exit code was " + exitValue + ". Output: " + outputStream.toString());
}
}
use of org.apache.commons.exec.DefaultExecutor 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;
}
use of org.apache.commons.exec.DefaultExecutor in project vespa by vespa-engine.
the class CommandExecutor method writeToOutputStream.
private void writeToOutputStream(ByteArrayOutputStream outputStream, String command) throws IOException {
CommandLine cmdLine = new CommandLine("/bin/bash");
cmdLine.addArgument("-c", false);
cmdLine.addArgument(command, false);
DefaultExecutor executor = new DefaultExecutor();
PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream);
executor.setStreamHandler(streamHandler);
executor.execute(cmdLine);
}
Aggregations