Remove path.home command-line setting

This commit is contained in:
Jason Tedor 2016-03-15 16:29:29 -04:00
parent 5994e91b08
commit 4ee90db13d
8 changed files with 22 additions and 36 deletions

View File

@ -188,10 +188,9 @@ final class Bootstrap {
node = new Node(nodeSettings); 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; Terminal terminal = foreground ? Terminal.DEFAULT : null;
Settings.Builder builder = Settings.builder(); Settings.Builder builder = Settings.builder();
builder.put(Environment.PATH_HOME_SETTING.getKey(), pathHome);
if (Strings.hasLength(pidFile)) { if (Strings.hasLength(pidFile)) {
builder.put(Environment.PIDFILE_SETTING.getKey(), pidFile); builder.put(Environment.PIDFILE_SETTING.getKey(), pidFile);
} }
@ -224,7 +223,6 @@ final class Bootstrap {
*/ */
static void init( static void init(
final boolean foreground, final boolean foreground,
final String pathHome,
final String pidFile, final String pidFile,
final Map<String, String> esSettings) throws Throwable { final Map<String, String> esSettings) throws Throwable {
// Set the system property before anything has a chance to trigger its use // Set the system property before anything has a chance to trigger its use
@ -234,7 +232,7 @@ final class Bootstrap {
INSTANCE = new Bootstrap(); INSTANCE = new Bootstrap();
Environment environment = initialSettings(foreground, pathHome, pidFile); Environment environment = initialSettings(foreground, pidFile);
Settings settings = environment.settings(); Settings settings = environment.settings();
LogConfigurator.configure(settings, true); LogConfigurator.configure(settings, true);
checkForCustomConfFile(); checkForCustomConfFile();

View File

@ -41,7 +41,6 @@ class Elasticsearch extends Command {
private final OptionSpec<Void> versionOption; private final OptionSpec<Void> versionOption;
private final OptionSpec<Void> daemonizeOption; private final OptionSpec<Void> daemonizeOption;
private final OptionSpec<String> pathHomeOption;
private final OptionSpec<String> pidfileOption; private final OptionSpec<String> pidfileOption;
private final OptionSpec<KeyValuePair> propertyOption; private final OptionSpec<KeyValuePair> propertyOption;
@ -54,8 +53,6 @@ class Elasticsearch extends Command {
daemonizeOption = parser.acceptsAll(Arrays.asList("d", "daemonize"), daemonizeOption = parser.acceptsAll(Arrays.asList("d", "daemonize"),
"Starts Elasticsearch in the background"); "Starts Elasticsearch in the background");
// TODO: in jopt-simple 5.0 this option type can be a Path // 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"), pidfileOption = parser.acceptsAll(Arrays.asList("p", "pidfile"),
"Creates a pid file in the specified path on start") "Creates a pid file in the specified path on start")
.withRequiredArg(); .withRequiredArg();
@ -80,7 +77,7 @@ class Elasticsearch extends Command {
@Override @Override
protected void execute(Terminal terminal, OptionSet options) throws Exception { protected void execute(Terminal terminal, OptionSet options) throws Exception {
if (options.has(versionOption)) { 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"); throw new UserError(ExitCodes.USAGE, "Elasticsearch version option is mutually exclusive with any other option");
} }
terminal.println("Version: " + org.elasticsearch.Version.CURRENT terminal.println("Version: " + org.elasticsearch.Version.CURRENT
@ -90,7 +87,6 @@ class Elasticsearch extends Command {
} }
final boolean daemonize = options.has(daemonizeOption); final boolean daemonize = options.has(daemonizeOption);
final String pathHome = pathHomeOption.value(options);
final String pidFile = pidfileOption.value(options); final String pidFile = pidfileOption.value(options);
final Map<String, String> esSettings = new HashMap<>(); final Map<String, String> esSettings = new HashMap<>();
@ -104,12 +100,12 @@ class Elasticsearch extends Command {
esSettings.put(kvp.key, kvp.value); 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<String, String> esSettings) { void init(final boolean daemonize, final String pidFile, final Map<String, String> esSettings) {
try { try {
Bootstrap.init(!daemonize, pathHome, pidFile, esSettings); Bootstrap.init(!daemonize, pidFile, esSettings);
} catch (final Throwable t) { } catch (final Throwable t) {
// format exceptions to the console in a special way // format exceptions to the console in a special way
// to avoid 2MB stacktraces from guice, etc. // to avoid 2MB stacktraces from guice, etc.

View File

@ -72,9 +72,6 @@ grant {
// set by ESTestCase to improve test reproducibility // set by ESTestCase to improve test reproducibility
// TODO: set this with gradle or some other way that repros with seed? // TODO: set this with gradle or some other way that repros with seed?
permission java.util.PropertyPermission "es.processors.override", "write"; 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 // TODO: these simply trigger a noisy warning if its unable to clear the properties
// fix that in randomizedtesting // fix that in randomizedtesting

View File

@ -45,14 +45,10 @@ public class ElasticsearchCliTests extends ESTestCase {
public void testVersion() throws Exception { public void testVersion() throws Exception {
runTestThatVersionIsMutuallyExclusiveToOtherOptions("-V", "-d"); runTestThatVersionIsMutuallyExclusiveToOtherOptions("-V", "-d");
runTestThatVersionIsMutuallyExclusiveToOtherOptions("-V", "--daemonize"); runTestThatVersionIsMutuallyExclusiveToOtherOptions("-V", "--daemonize");
runTestThatVersionIsMutuallyExclusiveToOtherOptions("-V", "-H", "/tmp/home");
runTestThatVersionIsMutuallyExclusiveToOtherOptions("-V", "--path.home", "/tmp/home");
runTestThatVersionIsMutuallyExclusiveToOtherOptions("-V", "-p", "/tmp/pid"); runTestThatVersionIsMutuallyExclusiveToOtherOptions("-V", "-p", "/tmp/pid");
runTestThatVersionIsMutuallyExclusiveToOtherOptions("-V", "--pidfile", "/tmp/pid"); runTestThatVersionIsMutuallyExclusiveToOtherOptions("-V", "--pidfile", "/tmp/pid");
runTestThatVersionIsMutuallyExclusiveToOtherOptions("--version", "-d"); runTestThatVersionIsMutuallyExclusiveToOtherOptions("--version", "-d");
runTestThatVersionIsMutuallyExclusiveToOtherOptions("--version", "--daemonize"); runTestThatVersionIsMutuallyExclusiveToOtherOptions("--version", "--daemonize");
runTestThatVersionIsMutuallyExclusiveToOtherOptions("--version", "-H", "/tmp/home");
runTestThatVersionIsMutuallyExclusiveToOtherOptions("--version", "--path.home", "/tmp/home");
runTestThatVersionIsMutuallyExclusiveToOtherOptions("--version", "-p", "/tmp/pid"); runTestThatVersionIsMutuallyExclusiveToOtherOptions("--version", "-p", "/tmp/pid");
runTestThatVersionIsMutuallyExclusiveToOtherOptions("--version", "--pidfile", "/tmp/pid"); runTestThatVersionIsMutuallyExclusiveToOtherOptions("--version", "--pidfile", "/tmp/pid");
runTestThatVersionIsReturned("-V"); runTestThatVersionIsReturned("-V");
@ -77,7 +73,7 @@ public class ElasticsearchCliTests extends ESTestCase {
} }
private void runTestVersion(int expectedStatus, Consumer<String> outputConsumer, String... args) throws Exception { private void runTestVersion(int expectedStatus, Consumer<String> 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 { public void testThatPidFileCanBeConfigured() throws Exception {
@ -92,7 +88,7 @@ public class ElasticsearchCliTests extends ESTestCase {
expectedStatus, expectedStatus,
expectedInit, expectedInit,
outputConsumer, outputConsumer,
(foreground, pathHome, pidFile, esSettings) -> assertThat(pidFile, equalTo("/tmp/pid")), (foreground, pidFile, esSettings) -> assertThat(pidFile, equalTo("/tmp/pid")),
args); args);
} }
@ -107,7 +103,7 @@ public class ElasticsearchCliTests extends ESTestCase {
ExitCodes.OK, ExitCodes.OK,
true, true,
output -> {}, output -> {},
(foreground, pathHome, pidFile, esSettings) -> assertThat(foreground, equalTo(!expectedDaemonize)), (foreground, pidFile, esSettings) -> assertThat(foreground, equalTo(!expectedDaemonize)),
args); args);
} }
@ -116,7 +112,7 @@ public class ElasticsearchCliTests extends ESTestCase {
ExitCodes.OK, ExitCodes.OK,
true, true,
output -> {}, output -> {},
(foreground, pathHome, pidFile, esSettings) -> { (foreground, pidFile, esSettings) -> {
assertThat(esSettings.size(), equalTo(2)); assertThat(esSettings.size(), equalTo(2));
assertThat(esSettings, hasEntry("es.foo", "bar")); assertThat(esSettings, hasEntry("es.foo", "bar"));
assertThat(esSettings, hasEntry("es.baz", "qux")); assertThat(esSettings, hasEntry("es.baz", "qux"));
@ -136,7 +132,7 @@ public class ElasticsearchCliTests extends ESTestCase {
ExitCodes.USAGE, ExitCodes.USAGE,
false, false,
output -> assertThat(output, containsString("Elasticsearch settings must be prefixed with [es.] but was [")), output -> assertThat(output, containsString("Elasticsearch settings must be prefixed with [es.] but was [")),
(foreground, pathHome, pidFile, esSettings) -> {}, (foreground, pidFile, esSettings) -> {},
args args
); );
} }
@ -146,7 +142,7 @@ public class ElasticsearchCliTests extends ESTestCase {
ExitCodes.USAGE, ExitCodes.USAGE,
false, false,
output -> assertThat(output, containsString("Elasticsearch setting [es.foo] must not be empty")), output -> assertThat(output, containsString("Elasticsearch setting [es.foo] must not be empty")),
(foreground, pathHome, pidFile, esSettings) -> {}, (foreground, pidFile, esSettings) -> {},
"-E", "es.foo=" "-E", "es.foo="
); );
} }
@ -156,12 +152,12 @@ public class ElasticsearchCliTests extends ESTestCase {
ExitCodes.USAGE, ExitCodes.USAGE,
false, false,
output -> assertThat(output, containsString("network.host is not a recognized option")), output -> assertThat(output, containsString("network.host is not a recognized option")),
(foreground, pathHome, pidFile, esSettings) -> {}, (foreground, pidFile, esSettings) -> {},
"--network.host"); "--network.host");
} }
private interface InitConsumer { private interface InitConsumer {
void accept(final boolean foreground, final String pathHome, final String pidFile, final Map<String, String> esSettings); void accept(final boolean foreground, final String pidFile, final Map<String, String> esSettings);
} }
private void runTest( private void runTest(
@ -175,9 +171,9 @@ public class ElasticsearchCliTests extends ESTestCase {
final AtomicBoolean init = new AtomicBoolean(); final AtomicBoolean init = new AtomicBoolean();
final int status = Elasticsearch.main(args, new Elasticsearch() { final int status = Elasticsearch.main(args, new Elasticsearch() {
@Override @Override
void init(final boolean daemonize, final String pathHome, final String pidFile, final Map<String, String> esSettings) { void init(final boolean daemonize, final String pidFile, final Map<String, String> esSettings) {
init.set(true); init.set(true);
initConsumer.accept(!daemonize, pathHome, pidFile, esSettings); initConsumer.accept(!daemonize, pidFile, esSettings);
} }
}, terminal); }, terminal);
assertThat(status, equalTo(expectedStatus)); assertThat(status, equalTo(expectedStatus));

View File

@ -99,7 +99,7 @@ fi
# Define other required variables # Define other required variables
PID_FILE="$PID_DIR/$NAME.pid" PID_FILE="$PID_DIR/$NAME.pid"
DAEMON=$ES_HOME/bin/elasticsearch 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_SIZE
export ES_HEAP_NEWSIZE export ES_HEAP_NEWSIZE

View File

@ -21,7 +21,6 @@ ExecStartPre=/usr/share/elasticsearch/bin/elasticsearch-systemd-pre-exec
ExecStart=/usr/share/elasticsearch/bin/elasticsearch \ ExecStart=/usr/share/elasticsearch/bin/elasticsearch \
-p ${PID_DIR}/elasticsearch.pid \ -p ${PID_DIR}/elasticsearch.pid \
-Ees.default.path.home=${ES_HOME} \
-Ees.default.path.logs=${LOG_DIR} \ -Ees.default.path.logs=${LOG_DIR} \
-Ees.default.path.data=${DATA_DIR} \ -Ees.default.path.data=${DATA_DIR} \
-Ees.default.path.conf=${CONF_DIR} -Ees.default.path.conf=${CONF_DIR}

View File

@ -126,11 +126,11 @@ export HOSTNAME
# manual parsing to find out, if process should be detached # manual parsing to find out, if process should be detached
daemonized=`echo $* | egrep -- '(^-d |-d$| -d |--daemonize$|--daemonize )'` daemonized=`echo $* | egrep -- '(^-d |-d$| -d |--daemonize$|--daemonize )'`
if [ -z "$daemonized" ] ; then if [ -z "$daemonized" ] ; then
exec "$JAVA" $JAVA_OPTS $ES_JAVA_OPTS -cp "$ES_CLASSPATH" \ exec "$JAVA" $JAVA_OPTS $ES_JAVA_OPTS -Des.path.home="$ES_HOME" -cp "$ES_CLASSPATH" \
org.elasticsearch.bootstrap.Elasticsearch --path.home "$ES_HOME" "$@" org.elasticsearch.bootstrap.Elasticsearch "$@"
else else
exec "$JAVA" $JAVA_OPTS $ES_JAVA_OPTS -cp "$ES_CLASSPATH" \ exec "$JAVA" $JAVA_OPTS $ES_JAVA_OPTS -Des.path.home="$ES_HOME" -cp "$ES_CLASSPATH" \
org.elasticsearch.bootstrap.Elasticsearch --path.home "$ES_HOME" "$@" <&- & org.elasticsearch.bootstrap.Elasticsearch "$@" <&- &
retval=$? retval=$?
pid=$! pid=$!
[ $retval -eq 0 ] || exit $retval [ $retval -eq 0 ] || exit $retval

View File

@ -152,7 +152,7 @@ if "%DATA_DIR%" == "" set DATA_DIR=%ES_HOME%\data
if "%CONF_DIR%" == "" set CONF_DIR=%ES_HOME%\config 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: =;% set JVM_OPTS=%JAVA_OPTS: =;%