Package org.rhq.core.system

Examples of org.rhq.core.system.ProcessExecution


        return set;
    }

    public boolean packageExists(SystemInfo sysinfo, String packageName) {
        boolean exists = false;
        ProcessExecution pe = new ProcessExecution("/bin/rpm");
        pe.setCaptureOutput(true);
        pe.setCheckExecutableExists(true);
        pe.setArguments(Arrays.asList("-qa", packageName));
        ProcessExecutionResults pr = sysinfo.executeProcess(pe);
        if (pr!=null && pr.getExitCode()!=null && pr.getExitCode() == 0) {
            String output = pr.getCapturedOutput();
            exists = output.contains(packageName);
        }
View Full Code Here


    public ProcessExecutionResults execute(String process, String... args) {
        List<String> argsList = Arrays.asList(args);
        if (log.isDebugEnabled()) {
            log.debug("Executing command " + this.buildCommandString(process, args));
        }
        ProcessExecution pe = new ProcessExecution(process);
        pe.setCaptureOutput(true);
        pe.setCheckExecutableExists(true);
        pe.setArguments(Arrays.asList(args));
        ProcessExecutionResults pr = resourceContext.getSystemInformation().executeProcess(pe);
        log.debug("Result " + pr.getExitCode());
        return pr;
    }
View Full Code Here

    private ProcessExecutionResults execute(String prefix, File executable, String... args) {
        File homeDir = serverPluginConfig.getHomeDir();
        File startScriptFile = executable.isAbsolute() ? executable : new File(homeDir, executable.getPath());

        ProcessExecution processExecution = ProcessExecutionUtility.createProcessExecution(prefix, startScriptFile);

        processExecution.setEnvironmentVariables(startScriptEnv);

        List<String> arguments = processExecution.getArguments();
        if (arguments == null) {
            arguments = new ArrayList<String>();
            processExecution.setArguments(arguments);
        }

        for (String arg : args) {
            if (arg != null) {
                arguments.add(arg);
            }
        }

        // When running on Windows 9x, standalone.bat and domain.bat need the cwd to be the AS bin dir in order to find
        // standalone.bat.conf and domain.bat.conf respectively.
        processExecution.setWorkingDirectory(startScriptFile.getParent());
        processExecution.setCaptureOutput(true);
        processExecution.setWaitForCompletion(MAX_PROCESS_WAIT_TIME);
        processExecution.setKillOnTimeout(false);

        if (waitTime > 0) {
            processExecution.setWaitForCompletion(waitTime);
        } else if (waitTime < 0) {
            processExecution.setWaitForCompletion(0);
        }

        processExecution.setKillOnTimeout(killOnTimeout);

        if (LOG.isDebugEnabled()) {
            LOG.debug("About to execute the following process: [" + processExecution + "]");
        }
View Full Code Here

     */
    private static ProcessExecutionResults executeExecutable(@NotNull
    SystemInfo sysInfo, String executable, String args, long wait, boolean captureOutput, boolean killOnTimeout)
        throws InvalidPluginConfigurationException {

        ProcessExecution processExecution = new ProcessExecution(executable);
        if (args != null) {
            processExecution.setArguments(args.split("[ \\t\\n]+"));
        }
        processExecution.setWaitForCompletion(wait);
        processExecution.setCaptureOutput(captureOutput);
        processExecution.setKillOnTimeout(killOnTimeout);

        ProcessExecutionResults results = sysInfo.executeProcess(processExecution);

        return results;
    }
View Full Code Here

        if (version == null && processInfo != null) {
            try {
                ProcExe executable = processInfo.priorSnaphot().getExecutable();
                if (executable != null) {
                    String postgresExe = executable.getName();
                    ProcessExecution execution = new ProcessExecution(postgresExe);
                    execution.setArguments(new String[] { "--version" });
                    execution.setCaptureOutput(true);
                    ProcessExecutionResults results = systemInfo.executeProcess(execution);
                    String versionInfo = results.getCapturedOutput();
                    Matcher m = VERSION_FROM_COMMANDLINE.matcher(versionInfo);
                    if (m.find()) {
                        version = versionInfo.substring(m.start(), m.end());
View Full Code Here

    private static ProcessExecutionResults executeExecutable(SystemInfo sysInfo, Configuration pluginConfig,
        String args, long wait, boolean captureOutput, boolean killOnTimeout, char escapeChar)
        throws InvalidPluginConfigurationException {

        ProcessExecution processExecution = getProcessExecutionInfo(pluginConfig);
        if (args != null) {
            if (isQuotingEnabled(escapeChar)) {
                processExecution.setArguments(ScriptArgumentParser.parse(args, escapeChar));
            } else {
                processExecution.setArguments(args.split(" "));
            }
        }
        processExecution.setCaptureOutput(captureOutput);
        processExecution.setWaitForCompletion(wait);
        processExecution.setKillOnTimeout(killOnTimeout);

        ProcessExecutionResults results = sysInfo.executeProcess(processExecution);

        return results;
    }
View Full Code Here

                throw new InvalidPluginConfigurationException("Bad plugin config: " + PLUGINCONFIG_ENVVARS
                    + ". Cause: " + e);
            }
        }

        ProcessExecution processExecution = new ProcessExecution(executable);
        processExecution.setEnvironmentVariables(envvars);
        processExecution.setWorkingDirectory(workingDir);

        return processExecution;
    }
View Full Code Here

        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()) {
View Full Code Here

        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()) {
View Full Code Here

     * @param resourceContext contains things like plugin config and system information
     */
    @SuppressWarnings("unchecked")
    public void init(ResourceContext resourceContext) {
        this.resourceContext = resourceContext;
        ProcessExecution processExecution = new ProcessExecution("/usr/bin/which");
        processExecution.setArguments(new String[] { "yum" });
        processExecution.setCaptureOutput(true);
        ProcessExecutionResults executionResults = resourceContext.getSystemInformation().executeProcess(
            processExecution);
        String capturedOutput = executionResults.getCapturedOutput();
        yum = (((capturedOutput == null) || "".equals(capturedOutput)) ? null : capturedOutput.trim());
        log.info("Using (yum) found at: " + yum);
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.