Merge pull request #12586 from rmuir/exit_value

Fix Bootstrap to not call System.exit
This commit is contained in:
Robert Muir 2015-08-03 05:27:08 -04:00
commit 20ed7c1724
3 changed files with 11 additions and 64 deletions

View File

@ -222,7 +222,7 @@ public class Bootstrap {
}
}
public static void main(String[] args) {
public static void main(String[] args) throws Throwable {
BootstrapCLIParser bootstrapCLIParser = new BootstrapCLIParser();
CliTool.ExitStatus status = bootstrapCLIParser.execute(args);
@ -239,28 +239,16 @@ public class Bootstrap {
foreground = false;
}
String stage = "Settings";
Tuple<Settings, Environment> tuple = initialSettings(foreground);
Settings settings = tuple.v1();
Environment environment = tuple.v2();
Settings settings = null;
Environment environment = null;
try {
Tuple<Settings, Environment> tuple = initialSettings(foreground);
settings = tuple.v1();
environment = tuple.v2();
if (environment.pidFile() != null) {
stage = "Pid";
PidFile.create(environment.pidFile(), true);
}
stage = "Logging";
setupLogging(settings, environment);
} catch (Exception e) {
String errorMessage = buildErrorMessage(stage, e);
sysError(errorMessage, true);
System.exit(3);
if (environment.pidFile() != null) {
PidFile.create(environment.pidFile(), true);
}
setupLogging(settings, environment);
if (System.getProperty("es.max-open-files", "false").equals("true")) {
ESLogger logger = Loggers.getLogger(Bootstrap.class);
logger.info("max_open_files [{}]", ProcessProbe.getInstance().getMaxFileDescriptorCount());
@ -272,7 +260,6 @@ public class Bootstrap {
logger.warn("jvm uses the client vm, make sure to run `java` with the server vm for best performance by adding `-server` to the command line");
}
stage = "Initialization";
try {
if (!foreground) {
Loggers.disableConsoleLogging();
@ -284,7 +271,6 @@ public class Bootstrap {
INSTANCE.setup(true, settings, environment);
stage = "Startup";
INSTANCE.start();
if (!foreground) {
@ -295,14 +281,9 @@ public class Bootstrap {
if (INSTANCE.node != null) {
logger = Loggers.getLogger(Bootstrap.class, INSTANCE.node.settings().get("name"));
}
String errorMessage = buildErrorMessage(stage, e);
if (foreground) {
sysError(errorMessage, true);
Loggers.disableConsoleLogging();
}
logger.error("Exception", e);
System.exit(3);
throw e;
}
}
@ -323,38 +304,4 @@ public class Bootstrap {
System.err.flush();
}
}
private static String buildErrorMessage(String stage, Throwable e) {
StringBuilder errorMessage = new StringBuilder("{").append(Version.CURRENT).append("}: ");
errorMessage.append(stage).append(" Failed ...\n");
if (e instanceof CreationException) {
CreationException createException = (CreationException) e;
Set<String> seenMessages = newHashSet();
int counter = 1;
for (Message message : createException.getErrorMessages()) {
String detailedMessage;
if (message.getCause() == null) {
detailedMessage = message.getMessage();
} else {
detailedMessage = ExceptionsHelper.detailedMessage(message.getCause(), true, 0);
}
if (detailedMessage == null) {
detailedMessage = message.getMessage();
}
if (seenMessages.contains(detailedMessage)) {
continue;
}
seenMessages.add(detailedMessage);
errorMessage.append("").append(counter++).append(") ").append(detailedMessage);
}
} else {
errorMessage.append("- ").append(ExceptionsHelper.detailedMessage(e, true, 0));
}
if (Loggers.getLogger(Bootstrap.class).isDebugEnabled()) {
errorMessage.append("\n").append(ExceptionsHelper.stackTrace(e));
}
return errorMessage.toString();
}
}

View File

@ -24,7 +24,7 @@ package org.elasticsearch.bootstrap;
*/
public class Elasticsearch extends Bootstrap {
public static void main(String[] args) {
public static void main(String[] args) throws Throwable {
Bootstrap.main(args);
}
}

View File

@ -25,7 +25,7 @@ package org.elasticsearch.bootstrap;
*/
public class ElasticsearchF {
public static void main(String[] args) {
public static void main(String[] args) throws Throwable {
System.setProperty("es.foreground", "yes");
Bootstrap.main(args);
}