use of com.sun.enterprise.universal.process.ProcessStreamDrainer in project Payara by payara.
the class SystemEnvironment method getCommandOutput.
protected String getCommandOutput(String... command) {
Process p = null;
ProcessStreamDrainer psd = null;
try {
ProcessBuilder pb = new ProcessBuilder(command);
p = pb.start();
psd = ProcessStreamDrainer.save("RegEnvCommandProcess", p);
return psd.getOutString();
} catch (Exception e) {
// ignore exception
return "";
} finally {
if (p != null) {
try {
p.getErrorStream().close();
} catch (IOException e) {
// ignore
}
try {
p.getInputStream().close();
} catch (IOException e) {
// ignore
}
p = null;
}
}
}
use of com.sun.enterprise.universal.process.ProcessStreamDrainer in project Payara by payara.
the class GFLauncher method getDeadProcessTrace.
private String getDeadProcessTrace(Process sp) throws GFLauncherException {
// returns null in case the process is NOT dead
try {
int ev = sp.exitValue();
ProcessStreamDrainer psd1 = getProcessStreamDrainer();
String output = psd1.getOutErrString();
String trace = strings.get("server_process_died", ev, output);
return trace;
} catch (IllegalThreadStateException e) {
// the process is still running and we are ok
return null;
}
}
use of com.sun.enterprise.universal.process.ProcessStreamDrainer in project Payara by payara.
the class StartDomainCommand method doAutoUpgrade.
/*
* If this domain needs to be upgraded and --upgrade wasn't
* specified, first start the domain to do the upgrade and
* then start the domain again for real.
*/
private void doAutoUpgrade(String mpv) throws GFLauncherException, MiniXmlParserException, CommandException {
if (upgrade || !launcher.needsAutoUpgrade())
return;
logger.info(strings.get("upgradeNeeded"));
info.setUpgrade(true);
launcher.setup();
launcher.launch();
Process p = launcher.getProcess();
int exitCode = -1;
try {
exitCode = p.waitFor();
} catch (InterruptedException ex) {
// should never happen
}
if (exitCode != SUCCESS) {
ProcessStreamDrainer psd = launcher.getProcessStreamDrainer();
String output = psd.getOutErrString();
if (ok(output))
throw new CommandException(strings.get("upgradeFailedOutput", info.getDomainName(), exitCode, output));
else
throw new CommandException(strings.get("upgradeFailed", info.getDomainName(), exitCode));
}
logger.info(strings.get("upgradeSuccessful"));
// need a new launcher to start the domain for real
createLauncher();
// continue with normal start...
}
use of com.sun.enterprise.universal.process.ProcessStreamDrainer in project Payara by payara.
the class StartServerHelper method waitForServer.
// TODO check the i18n messages
public void waitForServer() throws CommandException {
long startWait = System.currentTimeMillis();
if (!terse) {
// use stdout because logger always appends a newline
System.out.print(strings.get("WaitServer", serverOrDomainName) + " ");
}
boolean alive = false;
int count = 0;
pinged: while (!timedOut(startWait)) {
if (pidFile != null) {
if (logger.isLoggable(Level.FINER)) {
logger.finer("Check for pid file: " + pidFile);
}
if (pidFile.exists()) {
alive = true;
break pinged;
}
} else {
// if it is, the DAS is up
for (HostAndPort addr : addresses) {
if (NetUtils.isRunning(addr.getHost(), addr.getPort())) {
alive = true;
break pinged;
}
}
}
// if it isn't, startup failed
try {
Process p = launcher.getProcess();
int exitCode = p.exitValue();
// uh oh, DAS died
String sname;
if (info.isDomain()) {
sname = "domain " + info.getDomainName();
} else {
sname = "instance " + info.getInstanceName();
}
ProcessStreamDrainer psd = launcher.getProcessStreamDrainer();
String output = psd.getOutErrString();
if (ok(output)) {
throw new CommandException(strings.get("serverDiedOutput", sname, exitCode, output));
} else {
throw new CommandException(strings.get("serverDied", sname, exitCode));
}
} catch (GFLauncherException ex) {
// should never happen
} catch (IllegalThreadStateException ex) {
// process is still alive
}
// wait before checking again
try {
Thread.sleep(100);
if (!terse && count++ % 10 == 0) {
System.out.print(".");
}
} catch (InterruptedException ex) {
// don't care
}
}
if (!terse) {
System.out.println();
}
if (!alive) {
String msg;
String time = "" + (WAIT_FOR_DAS_TIME_MS / 1000);
if (info.isDomain()) {
msg = strings.get("serverNoStart", strings.get("DAS"), info.getDomainName(), time);
} else {
msg = strings.get("serverNoStart", strings.get("INSTANCE"), info.getInstanceName(), time);
}
throw new CommandException(msg);
}
}
Aggregations