private ProcessExecutionResults startNode(File basedir) { if (log.isDebugEnabled()) { log.debug("Starting node at " + basedir); } File binDir = new File(basedir, "bin"); File startScript; SystemInfo systemInfo = SystemInfoFactory.createSystemInfo(); ProcessExecution startScriptExe; if (systemInfo.getOperatingSystemType() == OperatingSystemType.WINDOWS) { startScript = new File(binDir, "cassandra.bat"); startScriptExe = createProcessExecution(null, startScript); } else { startScript = new File(binDir, "cassandra"); startScriptExe = createProcessExecution(null, startScript); startScriptExe.addArguments(Arrays.asList("-p", "cassandra.pid")); } startScriptExe.setWaitForCompletion(0); ProcessExecutionResults results = systemInfo.executeProcess(startScriptExe); if (log.isDebugEnabled()) { log.debug(startScript + " returned with exit code [" + results.getExitCode() + "]"); } return results; }
public OperationResult invokeOperation(String name, Configuration params) throws Exception { if (name.equals(EXECUTE_OPERATION)) { OperationResult operationResult = new OperationResult(); File scriptFile = getScriptFile(); SystemInfo systemInfo = this.resourceContext.getSystemInformation(); ProcessExecution processExecution = ProcessExecutionUtility.createProcessExecution(scriptFile); processExecution.setWaitForCompletion(1000L * 60 * 60); // 1 hour processExecution.setCaptureOutput(true); // TODO: Make the script's cwd configurable, but default it to the // directory containing the script. processExecution.setWorkingDirectory(scriptFile.getParent()); setEnvironmentVariables(processExecution); setCommandLineArguments(params, processExecution); if (log.isDebugEnabled()) { log.debug(processExecution); } ProcessExecutionResults processExecutionResults = systemInfo.executeProcess(processExecution); if (processExecutionResults.getError() != null) { throw new Exception(processExecutionResults.getError()); } Integer exitCode = processExecutionResults.getExitCode(); String output = processExecutionResults.getCapturedOutput(); // NOTE: // this // is // stdout // + // stderr Configuration complexResults = operationResult.getComplexResults(); complexResults.put(new PropertySimple(EXIT_CODE_RESULT_PROP, exitCode)); complexResults.put(new PropertySimple(OUTPUT_RESULT_PROP, output)); if (exitCode != null && exitCode != 0) { operationResult.setErrorMessage( "Exit code was '" + exitCode + "', see operation results for details"); } return operationResult; } else { throw new IllegalArgumentException("Unsupported operation: " + name); } }