Package org.rhq.core.system

Examples of org.rhq.core.system.ProcessExecution


        if ((prefix != null) && prefix.replaceAll("\\s", "").equals("")) {
            // all whitespace - normalize to null
            prefix = null;
        }

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

        // processExecution is initialized to the current process' env.  This isn't really right, it's the
        // rhq agent env.  Override this if the startScriptEnv property has been set.
        Map<String, String> startScriptEnv = startScriptConfig.getStartScriptEnv();
        if (!startScriptEnv.isEmpty()) {
            for (String envVarName : startScriptEnv.keySet()) {
                String envVarValue = startScriptEnv.get(envVarName);
                // TODO: If we migrate the AS7 util to a general util then hook it up
                // envVarValue = replacePropertyPatterns(envVarValue);
                startScriptEnv.put(envVarName, envVarValue);
            }
            processExecution.setEnvironmentVariables(startScriptEnv);
        } else {
            // set JAVA_HOME to the value of the deprecated 'javaHome' plugin config prop.
            setJavaHomeEnvironmentVariable(processExecution);
        }
View Full Code Here


        validateScriptFile(shutdownScriptFile,
            ApplicationServerPluginConfigurationProperties.SHUTDOWN_SCRIPT_CONFIG_PROP);
        Configuration pluginConfig = serverComponent.getResourceContext().getPluginConfiguration();
        String prefix = pluginConfig
            .getSimple(ApplicationServerPluginConfigurationProperties.SCRIPT_PREFIX_CONFIG_PROP).getStringValue();
        ProcessExecution processExecution = ProcessExecutionUtility.createProcessExecution(prefix, shutdownScriptFile);

        initProcessExecution(processExecution, shutdownScriptFile);

        setJavaHomeEnvironmentVariable(processExecution);
        String server = pluginConfig.getSimple(ApplicationServerPluginConfigurationProperties.NAMING_URL)
            .getStringValue();
        if (server != null) {
            processExecution.getArguments().add("--server=" + server);
        }

        String user = pluginConfig.getSimple(ApplicationServerComponent.PRINCIPAL_CONFIG_PROP).getStringValue();
        if (user != null) {
            processExecution.getArguments().add("--user=" + user);
        }

        String password = pluginConfig.getSimple(ApplicationServerComponent.CREDENTIALS_CONFIG_PROP).getStringValue();
        if (password != null) {
            processExecution.getArguments().add("--password=" + password);
        }

        processExecution.getArguments().add("--shutdown");

        /*
         * This tells shutdown.bat not to call the Windows PAUSE command, which
         * would cause the script to hang indefinitely waiting for input.
         * noinspection ConstantConditions
         */
        processExecution.getEnvironmentVariables().put("NOPAUSE", "1");

        if (log.isDebugEnabled()) {
            log.debug("About to execute the following process: [" + processExecution + "]");
        }
        SystemInfo systemInfo = serverComponent.getResourceContext().getSystemInformation();
View Full Code Here

                useJava = true;
            }
            useVersion = true;
        }

        ProcessExecution processExecution = ProcessExecutionUtility.createProcessExecution(versionScriptFile);
        if (useVersion) {
            List<String> args = new ArrayList<String>();
            if (useJava) {
                args.add("-classpath");
                args.add(catalinaHome + "/lib/catalina.jar");
                args.add("org.apache.catalina.util.ServerInfo");
            } else {
                args.add("version");
            }
            processExecution.setArguments(args);
        } else {
            TomcatServerOperationsDelegate.setProcessExecutionEnvironment(processExecution, catalinaHome, catalinaBase);
        }

        long timeout = 10000L;
        processExecution.setCaptureOutput(true);
        processExecution.setWaitForCompletion(timeout);
        processExecution.setKillOnTimeout(true);

        ProcessExecutionResults results = systemInfo.executeProcess(processExecution);
        String versionOutput = results.getCapturedOutput();

        String version = getVersionFromVersionScriptOutput(versionOutput);
View Full Code Here

        }

        Map<String, String> envvars = new HashMap<String, String>(System.getenv());
        envvars.put("RHQ_AGENT_DEBUG", "false"); // we don't want all that debug output in the beginning

        ProcessExecution exe = new ProcessExecution(this.launcherScript.getAbsolutePath());
        exe.setArguments(new String[] { arg });
        exe.setWorkingDirectory(this.launcherScript.getParent());
        exe.setCaptureOutput(true);
        exe.setWaitForCompletion(30000L);
        exe.setEnvironmentVariables(envvars);
        ProcessExecutionResults results = this.resourceContext.getSystemInformation().executeProcess(exe);
        Throwable error = results.getError();
        if (error != null) {
            throw new Exception("Failed to invoke [" + this.launcherScript + ' ' + arg + "]", error);
        }
View Full Code Here

        Thread thread = new Thread(new Runnable() {
            public void run() {
                try {
                    Thread.sleep(10000L); // this should be enough to return our operation results back
                    ProcessExecution exe = new ProcessExecution(script.getAbsolutePath());
                    exe.setArguments(new String[] { arg });
                    exe.setWorkingDirectory(script.getParent());
                    ProcessExecutionResults results = sysInfo.executeProcess(exe);
                    if (results != null && results.getError() != null) {
                        throw results.getError();
                    }
                } catch (Throwable t) {
View Full Code Here

        propertiesUpdater.update(properties);

        File binDir = new File(deploymentOptions.getBasedir(), "bin");
        SystemInfo systemInfo = SystemInfoFactory.createSystemInfo();

        ProcessExecution processExecution = getProcessExecution(binDir);
        ProcessExecutionResults results = systemInfo.executeProcess(processExecution);

        assertEquals(results.getExitCode(), (Integer) 0, "Cassandra failed to start: " + results.getCapturedOutput());
    }
View Full Code Here

        assertEquals(results.getExitCode(), (Integer) 0, "Cassandra failed to start: " + results.getCapturedOutput());
    }

    private ProcessExecution getProcessExecution(File binDir) {
        ProcessExecution startScriptExe;
        if (OperatingSystem.getInstance().getName().equals(OperatingSystem.NAME_WIN32)) {
            File startScript = new File(binDir, "cassandra.bat");
            startScriptExe = ProcessExecutionUtility.createProcessExecution(startScript);
        } else {
            File startScript = new File("./cassandra");
            startScriptExe = ProcessExecutionUtility.createProcessExecution(startScript);
            startScriptExe.setCheckExecutableExists(false);
        }
        startScriptExe.setWorkingDirectory(binDir.getAbsolutePath());
        startScriptExe.addArguments(asList("-p", "cassandra.pid"));
        startScriptExe.setCaptureOutput(true);
        return startScriptExe;
    }
View Full Code Here

    // Public  --------------------------------------------

    public static void checkExecutables() {
        // Make sure rpm is actually on the system
        ProcessExecution processExecution = new ProcessExecution("/usr/bin/which");
        processExecution.setArguments(new String[] { "rpm" });
        processExecution.setCaptureOutput(true);

        ProcessExecutionResults executionResults = systemInfo.executeProcess(processExecution);
        String capturedOutput = executionResults.getCapturedOutput();

        rpmExecutable = (((capturedOutput == null) || "".equals(capturedOutput)) ? null : capturedOutput.trim());
View Full Code Here

        /* Sample output from: rpm -qa
         * xorg-x11-fonts-ethiopic-7.2-3.fc8 bitmap-fonts-0.3-5.1.2.fc7 bluez-utils-cups-3.20-4.fc8
         *
         * In short, it's a list of installed packages.
         */
        ProcessExecution listRpmsProcess = new ProcessExecution(rpmExecutable);
        listRpmsProcess.setArguments(new String[] { "-qa" });
        listRpmsProcess.setCaptureOutput(true);

        ProcessExecutionResults executionResults = systemInfo.executeProcess(listRpmsProcess);
        String capturedOutput = executionResults.getCapturedOutput();

        // Process the resulting output
        if (capturedOutput == null) {
            return packages;
        }

        BufferedReader rpmNameReader = new BufferedReader(new StringReader(capturedOutput));

        String rpmName;

        while ((rpmName = rpmNameReader.readLine()) != null) {
            String name = null;
            String version = null;
            String architectureName = null;

            try {

                // Execute RPM query for each RPM
                ProcessExecution rpmQuery = new ProcessExecution(rpmExecutable);
                rpmQuery
                    .setArguments(new String[] {
                        "-q",
                        "--qf",
                        "%{NAME}\\n%{VERSION}.%{RELEASE}\\n%{ARCH}\\n%{INSTALLTIME}\\n%{FILEMD5S}\\n%{GROUP}\\n%{FILENAMES}\\n%{SIZE}\\n%{LICENSE}\\n%{DESCRIPTION}",
                        rpmName });
                rpmQuery.setCaptureOutput(true);

                ProcessExecutionResults rpmDataResults = systemInfo.executeProcess(rpmQuery);
                String rpmData = rpmDataResults.getCapturedOutput();

                BufferedReader rpmDataReader = new BufferedReader(new StringReader(rpmData));
View Full Code Here

        }

        Map<String, String> envvars = new HashMap<String, String>(System.getenv());
        envvars.put("RHQ_AGENT_DEBUG", "false"); // we don't want all that debug output in the beginning

        ProcessExecution exe = new ProcessExecution(this.launcherScript.getAbsolutePath());
        exe.setArguments(new String[] { arg });
        exe.setWorkingDirectory(this.launcherScript.getParent());
        exe.setCaptureOutput(true);
        exe.setWaitForCompletion(30000L);
        exe.setEnvironmentVariables(envvars);
        ProcessExecutionResults results = this.resourceContext.getSystemInformation().executeProcess(exe);
        Throwable error = results.getError();
        if (error != null) {
            throw new Exception("Failed to invoke [" + this.launcherScript + ' ' + arg + "]", error);
        }
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.