Package org.rhq.core.system

Examples of org.rhq.core.system.ProcessExecution


     * @param  file an executable or a batch file
     *
     * @return a process execution
     */
    public static ProcessExecution createProcessExecution(String prefix, File file) {
        ProcessExecution processExecution;

        List<String> prefixArgs;
        if (prefix != null) {
            // TODO (ips, 04/27/10): Ideally, the prefix should be a String[], not a String.
            prefixArgs = Arrays.asList(prefix.split("[ \t]+"));
        } else {
            prefixArgs = Collections.emptyList();
        }
        String executable;
        List<String> args = new ArrayList<String>();
        if (OS_IS_WINDOWS && isBatchFile(file)) {
            // Windows batch files cannot be executed directly - they must be passed as arguments to cmd.exe, e.g.
            // "C:\Windows\System32\cmd.exe /c C:\opt\jboss-as\bin\run.bat".
            executable = getCmdExeFile().getPath();
            args.add("/c");
            args.addAll(prefixArgs);
            args.add(file.getPath());
        } else {
            // UNIX
            if (prefixArgs.isEmpty()) {
                executable = file.getPath();
            } else {
                executable = prefixArgs.get(0);
                if (prefixArgs.size() > 1) {
                    args.addAll(prefixArgs.subList(1, prefixArgs.size()));
                }
                args.add(file.getPath());
            }
        }

        processExecution = new ProcessExecution(executable);
        processExecution.setArguments(args);

        // Start out with a copy of our own environment, since Windows needs
        // certain system environment variables to find DLLs, etc., and even
        // on UNIX, many scripts will require certain environment variables
        // (PATH, JAVA_HOME, etc.).
        // TODO (ips, 04/27/12): We probably should not just do this by default.
        Map<String, String> envVars = new LinkedHashMap<String, String>(System.getenv());
        processExecution.setEnvironmentVariables(envVars);

        // Many scripts (e.g. JBossAS scripts) assume their working directory is the directory containing the script.
        processExecution.setWorkingDirectory(file.getParent());

        return processExecution;
    }
View Full Code Here


            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 = ProcessExecutionUtility.createProcessExecution(startScript);
        } else {
            startScript = new File(binDir, "cassandra");
            startScriptExe = ProcessExecutionUtility.createProcessExecution(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() + "]");
        }
View Full Code Here

        out.println(MSG.getMsg(AgentI18NResourceKeys.EXECUTE_WILL_WAIT, Long.valueOf(waitTime)));

        // now execute the process
        SystemInfo systemInfo = SystemInfoFactory.createSystemInfo();
        ProcessExecution processExecution = new ProcessExecution(executable);
        processExecution.setArguments(procArgArray);
        processExecution.setEnvironmentVariables(environmentVars);
        processExecution.setWorkingDirectory(workingDir);
        processExecution.setWaitForCompletion(waitTime);
        processExecution.setCaptureOutput(capture);
        processExecution.setKillOnTimeout(killOnTimeout);

        ProcessExecutionResults results = systemInfo.executeProcess(processExecution);

        Integer exitCode = results.getExitCode();
        Throwable error = results.getError();
View Full Code Here

                args.add(aud.getAgentUpdateBinaryFile().getAbsolutePath());
                args.add("--pause=" + ((numThreadsStillAlive > 0) ? alivePause : pause));
                args.add("--update=" + this.agent.getAgentHomeDirectory());

                SystemInfo sysInfo = SystemInfoFactory.createSystemInfo();
                ProcessExecution processExecution = new ProcessExecution(javaExe);
                processExecution.setArguments(args);
                //processExecution.setEnvironmentVariables(envvars);
                processExecution.setWorkingDirectory(new File(this.agent.getAgentHomeDirectory()).getParent());
                processExecution.setCaptureOutput(false);
                processExecution.setWaitForCompletion(0);
                showMessage(AgentI18NResourceKeys.UPDATE_THREAD_EXECUTING_UPDATE_PROCESS, processExecution);
                ProcessExecutionResults results = sysInfo.executeProcess(processExecution);
                if (results.getError() != null) {
                    throw results.getError();
                }
View Full Code Here

        File smartctl = getSmartctl();
        if (smartctl != null) {

            for (String driveName : DRIVE_NAMES) {

                ProcessExecution proc = ProcessExecutionUtility.createProcessExecution("/usr/bin/sudo", smartctl.getAbsoluteFile());
                //new ProcessExecution("/usr/bin/sudo"); //smartctl.getAbsolutePath());
                proc.setArguments(new String[]{smartctl.getAbsolutePath(), "-i", driveName});
                proc.setCaptureOutput(true);
                proc.setWaitForCompletion(4000);
                ProcessExecutionResults results = context.getSystemInformation().executeProcess(proc);

                StringReader r = new StringReader(results.getCapturedOutput());
                BufferedReader br = new BufferedReader(r);
                String line = null;
View Full Code Here

    public void updateData() throws Exception {
        String prefix = context.getPluginConfiguration().getSimple("prefix").getStringValue();
        String command = context.getPluginConfiguration().getSimple("command").getStringValue();

        ProcessExecution proc;
        if (prefix != null) {
            proc = new ProcessExecution(prefix);
            proc.setArguments(new String[] { command, "--attributes", context.getResourceKey() });
        } else {
            proc = new ProcessExecution(command);
            proc.setArguments(new String[] { "--attributes", context.getResourceKey() });
        }

        proc.setCaptureOutput(true);
        proc.setWaitForCompletion(4000);
        ProcessExecutionResults results = context.getSystemInformation().executeProcess(proc);

        StringReader r = new StringReader(results.getCapturedOutput());
        BufferedReader br = new BufferedReader(r);
        String line = null;
View Full Code Here

        fis.close();
    }

    public void updateSmoltData() {

        ProcessExecution smolt = new ProcessExecution("/usr/bin/smoltSendProfile");
        smolt.setArguments(new String[]{"-p"});
        smolt.setCaptureOutput(true);
        smolt.setWaitForCompletion(4000);
        ProcessExecutionResults results = this.context.getSystemInformation().executeProcess(smolt);

        StringReader r = new StringReader(results.getCapturedOutput());
        BufferedReader br = new BufferedReader(r);
        String line = null;
View Full Code Here

        return result;
    }

    private ProcessExecutionResults execute(String path, String args) throws InvalidPluginConfigurationException {

        ProcessExecution processExecution = new ProcessExecution(path);
        SystemInfo sysInfo = this.resourceContext.getSystemInformation();

        if (args != null) {
            processExecution.setArguments(args.split(" "));
        }

        processExecution.setCaptureOutput(true);
        processExecution.setWaitForCompletion(1000L);
        processExecution.setKillOnTimeout(true);

        ProcessExecutionResults results = sysInfo.executeProcess(processExecution);

        return results;
    }
View Full Code Here

        if (!startScriptExists(binDir)) {
            OperationResult failure = new OperationResult("Failed to start Cassandra daemon");
            failure.setErrorMessage("Start script does not exists");
            return failure;
        }
        ProcessExecution scriptExe = getProcessExecution(binDir);
        SystemInfo systemInfo = getResourceContext().getSystemInformation();
        ProcessExecutionResults results = systemInfo.executeProcess(scriptExe);
        if (results.getError() == null) {
            return new OperationResult("Successfully started Cassandra daemon");
        } else {
View Full Code Here

        File file = new File(binDir, getStartScript());
        return file.exists() && !file.isDirectory();
    }

    private ProcessExecution getProcessExecution(File binDir) {
        ProcessExecution scriptExe;
        if (OperatingSystem.getInstance().getName().equals(OperatingSystem.NAME_WIN32)) {
            File startScript = new File(binDir, getStartScript());
            scriptExe = ProcessExecutionUtility.createProcessExecution(startScript);
        } else {
            // On Linux, when Cassandra is started with an absolute path, the command line is too long and is truncated
            // in /proc/pid/cmdline (beacuse of a long CLASSPATH made of absolute paths)
            // This prevents the process from being later discovered because the process query argument criteria
            // expects org.apache.cassandra.service.CassandraDaemon to be found
            File startScript = new File("./" + getStartScript());
            scriptExe = ProcessExecutionUtility.createProcessExecution(startScript);
            scriptExe.setCheckExecutableExists(false);
        }
        scriptExe.setWorkingDirectory(binDir.getAbsolutePath());
        scriptExe.addArguments(asList("-p", "cassandra.pid"));
        return scriptExe;
    }
View Full Code Here

TOP

Related Classes of org.rhq.core.system.ProcessExecution

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.