Search in sources :

Example 6 with ProcessManager

use of com.sun.enterprise.universal.process.ProcessManager in project Payara by payara.

the class WindowsService method uninstall.

private int uninstall() throws ProcessManagerException {
    if (info.dryRun || !targetWin32Exe.canExecute())
        return 0;
    // it is NOT an error to not be able to uninstall
    ProcessManager mgr = new ProcessManager(targetWin32Exe.getPath(), "uninstall");
    mgr.setEcho(false);
    mgr.execute();
    trace("Uninstall STDERR: " + mgr.getStderr());
    trace("Uninstall STDOUT: " + mgr.getStdout());
    return mgr.getExitValue();
}
Also used : ProcessManager(com.sun.enterprise.universal.process.ProcessManager)

Example 7 with ProcessManager

use of com.sun.enterprise.universal.process.ProcessManager in project Payara by payara.

the class NodeRunner method runAdminCommandOnLocalNode.

private int runAdminCommandOnLocalNode(Node node, StringBuilder output, boolean waitForReaderThreads, List<String> args, List<String> stdinLines) throws ProcessManagerException {
    args.add(0, AsadminInput.CLI_INPUT_OPTION);
    // specified to read from System.in
    args.add(1, AsadminInput.SYSTEM_IN_INDICATOR);
    List<String> fullcommand = new ArrayList<String>();
    String installDir = node.getInstallDirUnixStyle() + "/" + SystemPropertyConstants.getComponentName();
    if (!StringUtils.ok(installDir)) {
        throw new IllegalArgumentException("Node does not have an installDir");
    }
    File asadmin = new File(SystemPropertyConstants.getAsAdminScriptLocation(installDir));
    fullcommand.add(asadmin.getAbsolutePath());
    fullcommand.addAll(args);
    if (!asadmin.canExecute())
        throw new ProcessManagerException(asadmin.getAbsolutePath() + " is not executable.");
    lastCommandRun = commandListToString(fullcommand);
    trace("Running command locally: " + lastCommandRun);
    ProcessManager pm = new ProcessManager(fullcommand);
    pm.setStdinLines(stdinLines);
    // XXX should not need this after fix for 12777, but we seem to
    pm.waitForReaderThreads(waitForReaderThreads);
    // blocks until command is complete
    pm.execute();
    String stdout = pm.getStdout();
    String stderr = pm.getStderr();
    if (output != null) {
        if (StringUtils.ok(stdout)) {
            output.append(stdout);
        }
        if (StringUtils.ok(stderr)) {
            if (output.length() > 0) {
                output.append(NL);
            }
            output.append(stderr);
        }
    }
    return pm.getExitValue();
}
Also used : ProcessManagerException(com.sun.enterprise.universal.process.ProcessManagerException) ProcessManager(com.sun.enterprise.universal.process.ProcessManager)

Example 8 with ProcessManager

use of com.sun.enterprise.universal.process.ProcessManager in project Payara by payara.

the class SSHLauncher method generateKeyPair.

/**
 * Invoke ssh-keygen using ProcessManager API
 */
private boolean generateKeyPair() throws IOException {
    String keygenCmd = findSSHKeygen();
    if (logger.isLoggable(Level.FINER)) {
        logger.finer("Using " + keygenCmd + " to generate key pair");
    }
    if (!setupSSHDir()) {
        throw new IOException("Failed to set proper permissions on .ssh directory");
    }
    StringBuffer k = new StringBuffer();
    List<String> cmdLine = new ArrayList<String>();
    cmdLine.add(keygenCmd);
    k.append(keygenCmd);
    cmdLine.add("-t");
    k.append(" ").append("-t");
    cmdLine.add("rsa");
    k.append(" ").append("rsa");
    cmdLine.add("-N");
    k.append(" ").append("-N");
    if (rawKeyPassPhrase != null && rawKeyPassPhrase.length() > 0) {
        cmdLine.add(rawKeyPassPhrase);
        k.append(" ").append(getPrintablePassword(rawKeyPassPhrase));
    } else {
        // special handling for empty passphrase on Windows
        if (OS.isWindows()) {
            cmdLine.add("\"\"");
            k.append(" ").append("\"\"");
        } else {
            cmdLine.add("");
            k.append(" ").append("");
        }
    }
    cmdLine.add("-f");
    k.append(" ").append("-f");
    cmdLine.add(keyFile);
    k.append(" ").append(keyFile);
    // cmdLine.add("-vvv");
    ProcessManager pm = new ProcessManager(cmdLine);
    if (logger.isLoggable(Level.FINER)) {
        logger.finer("Command = " + k);
    }
    pm.setTimeoutMsec(DEFAULT_TIMEOUT_MSEC);
    if (logger.isLoggable(Level.FINER))
        pm.setEcho(true);
    else
        pm.setEcho(false);
    int exit;
    try {
        exit = pm.execute();
    } catch (ProcessManagerException ex) {
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("Error while executing ssh-keygen: " + ex.getMessage());
        }
        exit = 1;
    }
    if (exit == 0) {
        logger.info(keygenCmd + " successfully generated the identification " + keyFile);
    } else {
        if (logger.isLoggable(Level.FINER)) {
            logger.finer(pm.getStderr());
        }
        logger.info(keygenCmd + " failed");
    }
    return (exit == 0) ? true : false;
}
Also used : ProcessManagerException(com.sun.enterprise.universal.process.ProcessManagerException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ProcessManager(com.sun.enterprise.universal.process.ProcessManager)

Example 9 with ProcessManager

use of com.sun.enterprise.universal.process.ProcessManager in project Payara by payara.

the class SecureAdminConfigUpgrade method ensureKeyPairForInstanceAlias.

private void ensureKeyPairForInstanceAlias() throws IOException, NoSuchAlgorithmException, CertificateException, KeyStoreException, UnrecoverableKeyException, ProcessManagerException {
    /*
         * No need to add glassfish-instance to the keystore if it already exists.
         */
    final KeyStore ks = sslUtils().getKeyStore();
    if (ks.containsAlias(SecureAdmin.Duck.DEFAULT_INSTANCE_ALIAS)) {
        return;
    }
    /*
         * This is ugly but effective.  We need to add a new private key to 
         * the keystore and a new self-signed cert to the truststore.  To do so
         * we run keytool commands to change the on-disk stores, then we 
         * cause the in-memory copies to reload.
         */
    final File keyStoreFile = serverEnv.getJKS();
    final File trustStoreFile = new File(serverEnv.getConfigDirPath(), "cacerts.jks");
    final String pw = masterPassword();
    ProcessManager pm = new ProcessManager(new String[] { "keytool", "-genkey", "-keyalg", "RSA", "-keystore", keyStoreFile.getAbsolutePath(), "-alias", SecureAdmin.Duck.DEFAULT_INSTANCE_ALIAS, "-dname", getCertificateDN(), "-validity", "3650", "-keypass", pw, "-storepass", pw });
    pm.execute();
    if (pm.getExitValue() != 0) {
        final String err = pm.getStdout();
        throw new RuntimeException(err);
    }
    final File tempCertFile = new File(serverEnv.getConfigDirPath(), "temp.cer");
    tempCertFile.deleteOnExit();
    pm = new ProcessManager(new String[] { "keytool", "-exportcert", "-keystore", keyStoreFile.getAbsolutePath(), "-alias", SecureAdmin.Duck.DEFAULT_INSTANCE_ALIAS, "-keypass", pw, "-storepass", pw, "-file", tempCertFile.getAbsolutePath() });
    pm.execute();
    if (pm.getExitValue() != 0) {
        throw new RuntimeException(pm.getStderr());
    }
    pm = new ProcessManager(new String[] { "keytool", "-importcert", "-noprompt", "-trustcacerts", "-storepass", pw, "-keypass", pw, "-keystore", trustStoreFile.getAbsolutePath(), "-file", tempCertFile.getAbsolutePath(), "-alias", SecureAdmin.Duck.DEFAULT_INSTANCE_ALIAS });
    pm.execute();
    if (!tempCertFile.delete()) {
        logger.log(Level.FINE, "Unable to delete temp file {0}; continuing", tempCertFile.getAbsolutePath());
    }
    if (pm.getExitValue() != 0) {
        throw new RuntimeException(pm.getStderr());
    }
    /*
         * Reload the keystore and truststore from disk.
         */
    reload(sslUtils().getKeyStore(), keyStoreFile, pw);
    reload(sslUtils().getTrustStore(), serverEnv.getTrustStore(), pw);
}
Also used : KeyStore(java.security.KeyStore) File(java.io.File) ProcessManager(com.sun.enterprise.universal.process.ProcessManager)

Example 10 with ProcessManager

use of com.sun.enterprise.universal.process.ProcessManager in project Payara by payara.

the class NucleusTestUtils method cmdDetachWithOutput.

public static NadminReturn cmdDetachWithOutput(final File cmd, final int timeout, final String... args) {
    List<String> command = new ArrayList<String>();
    command.add(cmd.toString());
    command.add("--echo");
    command.add("--detach");
    command.addAll(Arrays.asList(args));
    ProcessManager pm = new ProcessManager(command);
    // the tests may be running unattended -- don't wait forever!
    pm.setTimeoutMsec(timeout);
    pm.setEcho(false);
    pm.setEnvironment(envp);
    int exit;
    String myErr = "";
    try {
        exit = pm.execute();
    } catch (ProcessManagerTimeoutException tex) {
        myErr = "\nProcessManagerTimeoutException: command timed out after " + timeout + " ms.";
        exit = 1;
    } catch (ProcessManagerException ex) {
        exit = 1;
    }
    NadminReturn ret = new NadminReturn(exit, pm.getStdout(), pm.getStderr() + myErr, args[0]);
    write(ret.outAndErr);
    return ret;
}
Also used : ProcessManagerTimeoutException(com.sun.enterprise.universal.process.ProcessManagerTimeoutException) ProcessManagerException(com.sun.enterprise.universal.process.ProcessManagerException) ArrayList(java.util.ArrayList) ProcessManager(com.sun.enterprise.universal.process.ProcessManager)

Aggregations

ProcessManager (com.sun.enterprise.universal.process.ProcessManager)13 ProcessManagerException (com.sun.enterprise.universal.process.ProcessManagerException)10 ArrayList (java.util.ArrayList)4 ProcessManagerTimeoutException (com.sun.enterprise.universal.process.ProcessManagerTimeoutException)2 File (java.io.File)2 IOException (java.io.IOException)1 KeyStore (java.security.KeyStore)1