Search in sources :

Example 1 with ProcessManager

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

the class LinuxService method createLink.

private void createLink(File link, String[] cmds) {
    try {
        ProcessManager mgr = new ProcessManager(cmds);
        mgr.setEcho(false);
        mgr.execute();
        trace("Create Link Output: " + mgr.getStdout() + mgr.getStderr());
        link.setExecutable(true, false);
        trace("Created link file: " + link);
    } catch (ProcessManagerException e) {
        throw new RuntimeException(Strings.get("ln_error", toString(cmds), e));
    }
}
Also used : ProcessManagerException(com.sun.enterprise.universal.process.ProcessManagerException) ProcessManager(com.sun.enterprise.universal.process.ProcessManager)

Example 2 with ProcessManager

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

the class SMFService method deleteServiceInternal.

@Override
public void deleteServiceInternal() {
    try {
        String serviceName = info.serviceName;
        if (!ok(serviceName))
            throw new RuntimeException(Strings.get("internal.error", "no service name is set"));
        String me = System.getProperty("user.name");
        StringBuilder sb = new StringBuilder();
        if (!isUserSmfAuthorized(me, sb))
            throw new RuntimeException(Strings.get("noSmfAuth", me, sb.toString()));
        ProcessManager pm = new ProcessManager(SVCADM, "disable", info.serviceName);
        pm.setEcho(false);
        pm.execute();
        pm = new ProcessManager(SVCCFG, "delete", info.serviceName);
        pm.setEcho(false);
        pm.execute();
    } catch (RuntimeException re) {
        throw re;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
Also used : ProcessManager(com.sun.enterprise.universal.process.ProcessManager) ProcessManagerException(com.sun.enterprise.universal.process.ProcessManagerException)

Example 3 with ProcessManager

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

the class CreateRemoteNodeCommand method execCommand.

/**
 * Invokes install-node using ProcessManager and returns the exit message/status.
 * @param cmdLine list of args
 * @param output contains output message
 * @return exit status of install-node
 *
 * This method was copied over from CreateNodeSshCommand on 9/14/11
 */
final int execCommand(List<String> cmdLine, StringBuilder output) {
    int exit = -1;
    List<String> fullcommand = new ArrayList<String>();
    String installDir = nodes.getDefaultLocalNode().getInstallDirUnixStyle() + "/glassfish";
    if (!StringUtils.ok(installDir)) {
        throw new IllegalArgumentException(Strings.get("create.node.ssh.no.installdir"));
    }
    File asadmin = new File(SystemPropertyConstants.getAsAdminScriptLocation(installDir));
    fullcommand.add(asadmin.getAbsolutePath());
    // if password auth is used for creating node, use the same auth mechanism for
    // install-node as well. The passwords are passed directly through input stream
    List<String> pass = new ArrayList<String>();
    if (remotePassword != null) {
        fullcommand.add("--passwordfile");
        fullcommand.add("-");
        pass = getPasswords();
    }
    fullcommand.add("--interactive=false");
    fullcommand.addAll(cmdLine);
    ProcessManager pm = new ProcessManager(fullcommand);
    if (!pass.isEmpty())
        pm.setStdinLines(pass);
    if (logger.isLoggable(Level.INFO)) {
        logger.info("Running command on DAS: " + commandListToString(fullcommand));
    }
    pm.setTimeoutMsec(DEFAULT_TIMEOUT_MSEC);
    if (logger.isLoggable(Level.FINER))
        pm.setEcho(true);
    else
        pm.setEcho(false);
    try {
        exit = pm.execute();
    } catch (ProcessManagerException ex) {
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("Error while executing command: " + ex.getMessage());
        }
        exit = 1;
    }
    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 exit;
}
Also used : ProcessManagerException(com.sun.enterprise.universal.process.ProcessManagerException) ProcessManager(com.sun.enterprise.universal.process.ProcessManager)

Example 4 with ProcessManager

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

the class DeleteNodeRemoteCommand method execCommand.

/**
 * Invokes install-node using ProcessManager and returns the exit message/status.
 * @param cmdLine list of args
 * @param output contains output message
 * @return exit status of uninstall-node
 */
private int execCommand(List<String> cmdLine, StringBuilder output) {
    int exit = -1;
    List<String> fullcommand = new ArrayList<String>();
    String installDir = nodes.getDefaultLocalNode().getInstallDirUnixStyle() + "/glassfish";
    if (!StringUtils.ok(installDir)) {
        throw new IllegalArgumentException(Strings.get("create.node.ssh.no.installdir"));
    }
    File asadmin = new File(SystemPropertyConstants.getAsAdminScriptLocation(installDir));
    fullcommand.add(asadmin.getAbsolutePath());
    // if password auth is used for deleting the node, use the same auth mechanism for
    // uinstall-node as well. The passwords are passed directly through input stream
    List<String> pass = new ArrayList<String>();
    if (remotepassword != null) {
        fullcommand.add("--passwordfile");
        fullcommand.add("-");
        pass = getPasswords();
    }
    fullcommand.add("--interactive=false");
    fullcommand.addAll(cmdLine);
    ProcessManager pm = new ProcessManager(fullcommand);
    if (!pass.isEmpty())
        pm.setStdinLines(pass);
    if (logger.isLoggable(Level.INFO)) {
        logger.info("Running command on DAS: " + commandListToString(fullcommand));
    }
    pm.setTimeoutMsec(DEFAULT_TIMEOUT_MSEC);
    if (logger.isLoggable(Level.FINER))
        pm.setEcho(true);
    else
        pm.setEcho(false);
    try {
        exit = pm.execute();
    } catch (ProcessManagerException ex) {
        if (logger.isLoggable(Level.FINE)) {
            logger.fine("Error while executing command: " + ex.getMessage());
        }
        exit = 1;
    }
    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 exit;
}
Also used : ProcessManagerException(com.sun.enterprise.universal.process.ProcessManagerException) ArrayList(java.util.ArrayList) File(java.io.File) ProcessManager(com.sun.enterprise.universal.process.ProcessManager)

Example 5 with ProcessManager

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

the class WindowsService method deleteServiceInternal.

@Override
public void deleteServiceInternal() {
    try {
        if (!isInstalled())
            throw new RuntimeException(Strings.get("not_installed"));
        if (!targetWin32Exe.canExecute())
            throw new RuntimeException(Strings.get("cant_exec"));
        ProcessManager pm = new ProcessManager(targetWin32Exe.getAbsolutePath(), "stop");
        pm.setEcho(false);
        pm.execute();
        pm = new ProcessManager(targetWin32Exe.getAbsolutePath(), "uninstall");
        pm.setEcho(false);
        pm.execute();
        trace("Uninstalled Windows Service");
        if (!targetWin32Exe.delete())
            targetWin32Exe.deleteOnExit();
        if (!targetXml.delete())
            targetXml.deleteOnExit();
        trace("deleted " + targetWin32Exe + targetXml);
        trace(toString());
    } catch (ProcessManagerException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : ProcessManagerException(com.sun.enterprise.universal.process.ProcessManagerException) 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