From 4ee90db13dc54744a9eb7b5d56df2ea4238014d8 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 15 Mar 2016 16:29:29 -0400 Subject: [PATCH] Remove path.home command-line setting --- .../elasticsearch/bootstrap/Bootstrap.java | 6 ++--- .../bootstrap/Elasticsearch.java | 12 ++++------ .../elasticsearch/bootstrap/security.policy | 3 --- .../bootstrap/ElasticsearchCliTests.java | 24 ++++++++----------- .../src/main/packaging/init.d/elasticsearch | 2 +- .../packaging/systemd/elasticsearch.service | 1 - .../src/main/resources/bin/elasticsearch | 8 +++---- .../src/main/resources/bin/service.bat | 2 +- 8 files changed, 22 insertions(+), 36 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java b/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java index a89bee0f4ac..2a8984e59d4 100644 --- a/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java +++ b/core/src/main/java/org/elasticsearch/bootstrap/Bootstrap.java @@ -188,10 +188,9 @@ final class Bootstrap { node = new Node(nodeSettings); } - private static Environment initialSettings(boolean foreground, String pathHome, String pidFile) { + private static Environment initialSettings(boolean foreground, 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)) { builder.put(Environment.PIDFILE_SETTING.getKey(), pidFile); } @@ -224,7 +223,6 @@ final class Bootstrap { */ static void init( final boolean foreground, - final String pathHome, final String pidFile, final Map esSettings) throws Throwable { // Set the system property before anything has a chance to trigger its use @@ -234,7 +232,7 @@ final class Bootstrap { INSTANCE = new Bootstrap(); - Environment environment = initialSettings(foreground, pathHome, pidFile); + Environment environment = initialSettings(foreground, pidFile); Settings settings = environment.settings(); LogConfigurator.configure(settings, true); checkForCustomConfFile(); diff --git a/core/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java b/core/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java index d15f72e8655..0cc952907c0 100644 --- a/core/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java +++ b/core/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java @@ -41,7 +41,6 @@ class Elasticsearch extends Command { private final OptionSpec versionOption; private final OptionSpec daemonizeOption; - private final OptionSpec pathHomeOption; private final OptionSpec pidfileOption; private final OptionSpec propertyOption; @@ -54,8 +53,6 @@ class Elasticsearch extends Command { daemonizeOption = parser.acceptsAll(Arrays.asList("d", "daemonize"), "Starts Elasticsearch in the background"); // TODO: in jopt-simple 5.0 this option type can be a Path - pathHomeOption = parser.acceptsAll(Arrays.asList("H", "path.home"), "").withRequiredArg(); - // TODO: in jopt-simple 5.0 this option type can be a Path pidfileOption = parser.acceptsAll(Arrays.asList("p", "pidfile"), "Creates a pid file in the specified path on start") .withRequiredArg(); @@ -80,7 +77,7 @@ class Elasticsearch extends Command { @Override protected void execute(Terminal terminal, OptionSet options) throws Exception { if (options.has(versionOption)) { - if (options.has(daemonizeOption) || options.has(pathHomeOption) || options.has(pidfileOption)) { + if (options.has(daemonizeOption) || options.has(pidfileOption)) { throw new UserError(ExitCodes.USAGE, "Elasticsearch version option is mutually exclusive with any other option"); } terminal.println("Version: " + org.elasticsearch.Version.CURRENT @@ -90,7 +87,6 @@ class Elasticsearch extends Command { } final boolean daemonize = options.has(daemonizeOption); - final String pathHome = pathHomeOption.value(options); final String pidFile = pidfileOption.value(options); final Map esSettings = new HashMap<>(); @@ -104,12 +100,12 @@ class Elasticsearch extends Command { esSettings.put(kvp.key, kvp.value); } - init(daemonize, pathHome, pidFile, esSettings); + init(daemonize, pidFile, esSettings); } - void init(final boolean daemonize, final String pathHome, final String pidFile, final Map esSettings) { + void init(final boolean daemonize, final String pidFile, final Map esSettings) { try { - Bootstrap.init(!daemonize, pathHome, pidFile, esSettings); + Bootstrap.init(!daemonize, 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/main/resources/org/elasticsearch/bootstrap/security.policy b/core/src/main/resources/org/elasticsearch/bootstrap/security.policy index 4909959015b..10bf8b2a158 100644 --- a/core/src/main/resources/org/elasticsearch/bootstrap/security.policy +++ b/core/src/main/resources/org/elasticsearch/bootstrap/security.policy @@ -72,9 +72,6 @@ grant { // set by ESTestCase to improve test reproducibility // TODO: set this with gradle or some other way that repros with seed? permission java.util.PropertyPermission "es.processors.override", "write"; - // set by CLIToolTestCase - // TODO: do this differently? or test commandline tools differently? - permission java.util.PropertyPermission "es.default.path.home", "write"; // TODO: these simply trigger a noisy warning if its unable to clear the properties // fix that in randomizedtesting diff --git a/core/src/test/java/org/elasticsearch/bootstrap/ElasticsearchCliTests.java b/core/src/test/java/org/elasticsearch/bootstrap/ElasticsearchCliTests.java index fe1eeb8b5a6..51274af9a01 100644 --- a/core/src/test/java/org/elasticsearch/bootstrap/ElasticsearchCliTests.java +++ b/core/src/test/java/org/elasticsearch/bootstrap/ElasticsearchCliTests.java @@ -45,14 +45,10 @@ public class ElasticsearchCliTests extends ESTestCase { public void testVersion() throws Exception { runTestThatVersionIsMutuallyExclusiveToOtherOptions("-V", "-d"); runTestThatVersionIsMutuallyExclusiveToOtherOptions("-V", "--daemonize"); - runTestThatVersionIsMutuallyExclusiveToOtherOptions("-V", "-H", "/tmp/home"); - runTestThatVersionIsMutuallyExclusiveToOtherOptions("-V", "--path.home", "/tmp/home"); runTestThatVersionIsMutuallyExclusiveToOtherOptions("-V", "-p", "/tmp/pid"); runTestThatVersionIsMutuallyExclusiveToOtherOptions("-V", "--pidfile", "/tmp/pid"); runTestThatVersionIsMutuallyExclusiveToOtherOptions("--version", "-d"); runTestThatVersionIsMutuallyExclusiveToOtherOptions("--version", "--daemonize"); - runTestThatVersionIsMutuallyExclusiveToOtherOptions("--version", "-H", "/tmp/home"); - runTestThatVersionIsMutuallyExclusiveToOtherOptions("--version", "--path.home", "/tmp/home"); runTestThatVersionIsMutuallyExclusiveToOtherOptions("--version", "-p", "/tmp/pid"); runTestThatVersionIsMutuallyExclusiveToOtherOptions("--version", "--pidfile", "/tmp/pid"); runTestThatVersionIsReturned("-V"); @@ -77,7 +73,7 @@ public class ElasticsearchCliTests extends ESTestCase { } private void runTestVersion(int expectedStatus, Consumer outputConsumer, String... args) throws Exception { - runTest(expectedStatus, false, outputConsumer, (foreground, pathHome, pidFile, esSettings) -> {}, args); + runTest(expectedStatus, false, outputConsumer, (foreground, pidFile, esSettings) -> {}, args); } public void testThatPidFileCanBeConfigured() throws Exception { @@ -92,7 +88,7 @@ public class ElasticsearchCliTests extends ESTestCase { expectedStatus, expectedInit, outputConsumer, - (foreground, pathHome, pidFile, esSettings) -> assertThat(pidFile, equalTo("/tmp/pid")), + (foreground, pidFile, esSettings) -> assertThat(pidFile, equalTo("/tmp/pid")), args); } @@ -107,7 +103,7 @@ public class ElasticsearchCliTests extends ESTestCase { ExitCodes.OK, true, output -> {}, - (foreground, pathHome, pidFile, esSettings) -> assertThat(foreground, equalTo(!expectedDaemonize)), + (foreground, pidFile, esSettings) -> assertThat(foreground, equalTo(!expectedDaemonize)), args); } @@ -116,7 +112,7 @@ public class ElasticsearchCliTests extends ESTestCase { ExitCodes.OK, true, output -> {}, - (foreground, pathHome, pidFile, esSettings) -> { + (foreground, pidFile, esSettings) -> { assertThat(esSettings.size(), equalTo(2)); assertThat(esSettings, hasEntry("es.foo", "bar")); assertThat(esSettings, hasEntry("es.baz", "qux")); @@ -136,7 +132,7 @@ public class ElasticsearchCliTests extends ESTestCase { ExitCodes.USAGE, false, output -> assertThat(output, containsString("Elasticsearch settings must be prefixed with [es.] but was [")), - (foreground, pathHome, pidFile, esSettings) -> {}, + (foreground, pidFile, esSettings) -> {}, args ); } @@ -146,7 +142,7 @@ public class ElasticsearchCliTests extends ESTestCase { ExitCodes.USAGE, false, output -> assertThat(output, containsString("Elasticsearch setting [es.foo] must not be empty")), - (foreground, pathHome, pidFile, esSettings) -> {}, + (foreground, pidFile, esSettings) -> {}, "-E", "es.foo=" ); } @@ -156,12 +152,12 @@ public class ElasticsearchCliTests extends ESTestCase { ExitCodes.USAGE, false, output -> assertThat(output, containsString("network.host is not a recognized option")), - (foreground, pathHome, pidFile, esSettings) -> {}, + (foreground, pidFile, esSettings) -> {}, "--network.host"); } private interface InitConsumer { - void accept(final boolean foreground, final String pathHome, final String pidFile, final Map esSettings); + void accept(final boolean foreground, final String pidFile, final Map esSettings); } private void runTest( @@ -175,9 +171,9 @@ public class ElasticsearchCliTests extends ESTestCase { final AtomicBoolean init = new AtomicBoolean(); final int status = Elasticsearch.main(args, new Elasticsearch() { @Override - void init(final boolean daemonize, final String pathHome, final String pidFile, final Map esSettings) { + void init(final boolean daemonize, final String pidFile, final Map esSettings) { init.set(true); - initConsumer.accept(!daemonize, pathHome, pidFile, esSettings); + initConsumer.accept(!daemonize, pidFile, esSettings); } }, terminal); assertThat(status, equalTo(expectedStatus)); diff --git a/distribution/deb/src/main/packaging/init.d/elasticsearch b/distribution/deb/src/main/packaging/init.d/elasticsearch index e2d857a7ffe..1476a520c1d 100755 --- a/distribution/deb/src/main/packaging/init.d/elasticsearch +++ b/distribution/deb/src/main/packaging/init.d/elasticsearch @@ -99,7 +99,7 @@ fi # Define other required variables PID_FILE="$PID_DIR/$NAME.pid" DAEMON=$ES_HOME/bin/elasticsearch -DAEMON_OPTS="-d -p $PID_FILE -Ees.default.path.home=$ES_HOME -Ees.default.path.logs=$LOG_DIR -Ees.default.path.data=$DATA_DIR -Ees.default.path.conf=$CONF_DIR" +DAEMON_OPTS="-d -p $PID_FILE -Ees.default.path.logs=$LOG_DIR -Ees.default.path.data=$DATA_DIR -Ees.default.path.conf=$CONF_DIR" export ES_HEAP_SIZE export ES_HEAP_NEWSIZE diff --git a/distribution/src/main/packaging/systemd/elasticsearch.service b/distribution/src/main/packaging/systemd/elasticsearch.service index 6aa6efeadde..1aed30ac968 100644 --- a/distribution/src/main/packaging/systemd/elasticsearch.service +++ b/distribution/src/main/packaging/systemd/elasticsearch.service @@ -21,7 +21,6 @@ ExecStartPre=/usr/share/elasticsearch/bin/elasticsearch-systemd-pre-exec ExecStart=/usr/share/elasticsearch/bin/elasticsearch \ -p ${PID_DIR}/elasticsearch.pid \ - -Ees.default.path.home=${ES_HOME} \ -Ees.default.path.logs=${LOG_DIR} \ -Ees.default.path.data=${DATA_DIR} \ -Ees.default.path.conf=${CONF_DIR} diff --git a/distribution/src/main/resources/bin/elasticsearch b/distribution/src/main/resources/bin/elasticsearch index 0d0e0069ae2..253ee1ee1f5 100755 --- a/distribution/src/main/resources/bin/elasticsearch +++ b/distribution/src/main/resources/bin/elasticsearch @@ -126,11 +126,11 @@ export HOSTNAME # manual parsing to find out, if process should be detached daemonized=`echo $* | egrep -- '(^-d |-d$| -d |--daemonize$|--daemonize )'` if [ -z "$daemonized" ] ; then - exec "$JAVA" $JAVA_OPTS $ES_JAVA_OPTS -cp "$ES_CLASSPATH" \ - org.elasticsearch.bootstrap.Elasticsearch --path.home "$ES_HOME" "$@" + exec "$JAVA" $JAVA_OPTS $ES_JAVA_OPTS -Des.path.home="$ES_HOME" -cp "$ES_CLASSPATH" \ + org.elasticsearch.bootstrap.Elasticsearch "$@" else - exec "$JAVA" $JAVA_OPTS $ES_JAVA_OPTS -cp "$ES_CLASSPATH" \ - org.elasticsearch.bootstrap.Elasticsearch --path.home "$ES_HOME" "$@" <&- & + exec "$JAVA" $JAVA_OPTS $ES_JAVA_OPTS -Des.path.home="$ES_HOME" -cp "$ES_CLASSPATH" \ + org.elasticsearch.bootstrap.Elasticsearch "$@" <&- & retval=$? pid=$! [ $retval -eq 0 ] || exit $retval diff --git a/distribution/src/main/resources/bin/service.bat b/distribution/src/main/resources/bin/service.bat index 22242e36ff9..2786c87a634 100644 --- a/distribution/src/main/resources/bin/service.bat +++ b/distribution/src/main/resources/bin/service.bat @@ -152,7 +152,7 @@ if "%DATA_DIR%" == "" set DATA_DIR=%ES_HOME%\data if "%CONF_DIR%" == "" set CONF_DIR=%ES_HOME%\config -set ES_PARAMS=-Delasticsearch;-Des.path.home="%ES_HOME%";-Des.default.path.home="%ES_HOME%";-Des.default.path.logs="%LOG_DIR%";-Des.default.path.data="%DATA_DIR%";-Des.default.path.conf="%CONF_DIR%" +set ES_PARAMS=-Delasticsearch;-Des.path.home="%ES_HOME%";-Des.default.path.logs="%LOG_DIR%";-Des.default.path.data="%DATA_DIR%";-Des.default.path.conf="%CONF_DIR%" set JVM_OPTS=%JAVA_OPTS: =;%