diff --git a/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java b/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java index 3ad592af635..a89bee0f4ac 100644 --- a/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java +++ b/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java @@ -188,8 +188,8 @@ final class Bootstrap { node = new Node(nodeSettings); } - private static Environment initialSettings(boolean daemonize, String pathHome, String pidFile) { - Terminal terminal = daemonize ? null : Terminal.DEFAULT; + private static Environment initialSettings(boolean foreground, String pathHome, String pidFile) { + Terminal terminal = foreground ? Terminal.DEFAULT : null; Settings.Builder builder = Settings.builder(); builder.put(Environment.PATH_HOME_SETTING.getKey(), pathHome); if (Strings.hasLength(pidFile)) { @@ -223,7 +223,7 @@ final class Bootstrap { * to startup elasticsearch. */ static void init( - final boolean daemonize, + final boolean foreground, final String pathHome, final String pidFile, final Map esSettings) throws Throwable { @@ -234,7 +234,7 @@ final class Bootstrap { INSTANCE = new Bootstrap(); - Environment environment = initialSettings(daemonize, pathHome, pidFile); + Environment environment = initialSettings(foreground, pathHome, pidFile); Settings settings = environment.settings(); LogConfigurator.configure(settings, true); checkForCustomConfFile(); @@ -250,7 +250,7 @@ final class Bootstrap { } try { - if (daemonize) { + if (!foreground) { Loggers.disableConsoleLogging(); closeSystOut(); } @@ -265,12 +265,12 @@ final class Bootstrap { INSTANCE.start(); - if (daemonize) { + if (!foreground) { closeSysError(); } } catch (Throwable e) { // disable console logging, so user does not see the exception twice (jvm will show it already) - if (!daemonize) { + if (foreground) { Loggers.disableConsoleLogging(); } ESLogger logger = Loggers.getLogger(Bootstrap.class); @@ -290,7 +290,7 @@ final class Bootstrap { logger.error("Exception", e); } // re-enable it if appropriate, so they can see any logging during the shutdown process - if (!daemonize) { + if (foreground) { Loggers.enableConsoleLogging(); } diff --git a/core/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java b/core/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java index dfe49c52e98..f492f06cd5a 100644 --- a/core/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java +++ b/core/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java @@ -109,7 +109,7 @@ class Elasticsearch extends Command { void init(final boolean daemonize, final String pathHome, final String pidFile, final Map esSettings) { try { - Bootstrap.init(daemonize, pathHome, pidFile, esSettings); + Bootstrap.init(!daemonize, pathHome, pidFile, esSettings); } catch (final Throwable t) { // format exceptions to the console in a special way // to avoid 2MB stacktraces from guice, etc. diff --git a/core/src/test/java/org/elasticsearch/bootstrap/ElasticsearchCommandLineParsingTests.java b/core/src/test/java/org/elasticsearch/bootstrap/ElasticsearchCommandLineParsingTests.java index 0d70cb8fba5..62603412a2c 100644 --- a/core/src/test/java/org/elasticsearch/bootstrap/ElasticsearchCommandLineParsingTests.java +++ b/core/src/test/java/org/elasticsearch/bootstrap/ElasticsearchCommandLineParsingTests.java @@ -77,7 +77,7 @@ public class ElasticsearchCommandLineParsingTests extends ESTestCase { } private void runTestVersion(int expectedStatus, Consumer outputConsumer, String... args) throws Exception { - runTest(expectedStatus, false, outputConsumer, (daemonize, pathHome, pidFile, esSettings) -> {}, args); + runTest(expectedStatus, false, outputConsumer, (foreground, pathHome, pidFile, esSettings) -> {}, args); } public void testThatPidFileCanBeConfigured() throws Exception { @@ -92,7 +92,7 @@ public class ElasticsearchCommandLineParsingTests extends ESTestCase { expectedStatus, expectedInit, outputConsumer, - (daemonize, pathHome, pidFile, esSettings) -> assertThat(pidFile, equalTo("/tmp/pid")), + (foreground, pathHome, pidFile, esSettings) -> assertThat(pidFile, equalTo("/tmp/pid")), args); } @@ -107,7 +107,7 @@ public class ElasticsearchCommandLineParsingTests extends ESTestCase { ExitCodes.OK, true, output -> {}, - (daemonize, pathHome, pidFile, esSettings) -> assertThat(daemonize, equalTo(expectedDaemonize)), + (foreground, pathHome, pidFile, esSettings) -> assertThat(foreground, equalTo(!expectedDaemonize)), args); } @@ -116,7 +116,7 @@ public class ElasticsearchCommandLineParsingTests extends ESTestCase { ExitCodes.OK, true, output -> {}, - (daemonize, pathHome, pidFile, esSettings) -> { + (foreground, pathHome, pidFile, esSettings) -> { assertThat(esSettings.size(), equalTo(2)); assertThat(esSettings, hasEntry("es.foo", "bar")); assertThat(esSettings, hasEntry("es.baz", "qux")); @@ -136,7 +136,7 @@ public class ElasticsearchCommandLineParsingTests extends ESTestCase { ExitCodes.USAGE, false, output -> assertThat(output, containsString("Elasticsearch settings must be prefixed with [es.] but was [")), - (daemonize, pathHome, pidFile, esSettings) -> {}, + (foreground, pathHome, pidFile, esSettings) -> {}, args ); } @@ -146,7 +146,7 @@ public class ElasticsearchCommandLineParsingTests extends ESTestCase { ExitCodes.USAGE, false, output -> assertThat(output, containsString("Elasticsearch setting [es.foo] must not be empty")), - (daemonize, pathHome, pidFile, esSettings) -> {}, + (foreground, pathHome, pidFile, esSettings) -> {}, "-E", "es.foo=" ); } @@ -156,12 +156,12 @@ public class ElasticsearchCommandLineParsingTests extends ESTestCase { ExitCodes.USAGE, false, output -> assertThat(output, containsString("network.host is not a recognized option")), - (daemonize, pathHome, pidFile, esSettings) -> {}, + (foreground, pathHome, pidFile, esSettings) -> {}, "--network.host"); } private interface InitConsumer { - void accept(final boolean daemonize, final String pathHome, final String pidFile, final Map esSettings); + void accept(final boolean foreground, final String pathHome, final String pidFile, final Map esSettings); } private void runTest( @@ -177,7 +177,7 @@ public class ElasticsearchCommandLineParsingTests extends ESTestCase { @Override void init(final boolean daemonize, final String pathHome, final String pidFile, final Map esSettings) { init.set(true); - initConsumer.accept(daemonize, pathHome, pidFile, esSettings); + initConsumer.accept(!daemonize, pathHome, pidFile, esSettings); } }, terminal); assertThat(status, equalTo(expectedStatus));