use of com.sun.enterprise.universal.process.ProcessManagerException 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));
}
}
use of com.sun.enterprise.universal.process.ProcessManagerException 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;
}
use of com.sun.enterprise.universal.process.ProcessManagerException 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;
}
use of com.sun.enterprise.universal.process.ProcessManagerException 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);
}
}
use of com.sun.enterprise.universal.process.ProcessManagerException 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();
}
Aggregations