diff --git a/core/src/main/java/org/elasticsearch/cli/EnvironmentAwareCommand.java b/core/src/main/java/org/elasticsearch/cli/EnvironmentAwareCommand.java index e06d227a24c..a1eacaafe15 100644 --- a/core/src/main/java/org/elasticsearch/cli/EnvironmentAwareCommand.java +++ b/core/src/main/java/org/elasticsearch/cli/EnvironmentAwareCommand.java @@ -33,18 +33,16 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Locale; import java.util.Map; +import java.util.Objects; /** A cli command which requires an {@link org.elasticsearch.env.Environment} to use current paths and settings. */ public abstract class EnvironmentAwareCommand extends Command { private final OptionSpec settingOption; - private final OptionSpec pathConfOption; public EnvironmentAwareCommand(String description) { super(description); this.settingOption = parser.accepts("E", "Configure a setting").withRequiredArg().ofType(KeyValuePair.class); - this.pathConfOption = - parser.acceptsAll(Arrays.asList("c", "path.conf"), "Configure config path").withRequiredArg().ofType(String.class); } @Override @@ -70,13 +68,17 @@ public abstract class EnvironmentAwareCommand extends Command { putSystemPropertyIfSettingIsMissing(settings, "path.home", "es.path.home"); putSystemPropertyIfSettingIsMissing(settings, "path.logs", "es.path.logs"); - final String pathConf = pathConfOption.value(options); + final String pathConf = System.getProperty("es.path.conf"); + if (pathConf == null) { + throw new UserException(ExitCodes.CONFIG, "the system property es.path.conf must be set"); + } + execute(terminal, options, createEnv(terminal, settings, getConfigPath(pathConf))); } @SuppressForbidden(reason = "need path to construct environment") private static Path getConfigPath(final String pathConf) { - return pathConf == null ? null : Paths.get(pathConf); + return Paths.get(pathConf); } /** Create an {@link Environment} for the command to use. Overrideable for tests. */ diff --git a/distribution/src/main/resources/bin/elasticsearch b/distribution/src/main/resources/bin/elasticsearch index 29b271f52fb..86d99f012f5 100755 --- a/distribution/src/main/resources/bin/elasticsearch +++ b/distribution/src/main/resources/bin/elasticsearch @@ -38,17 +38,27 @@ ES_JVM_OPTIONS="$CONF_DIR"/jvm.options ES_JAVA_OPTS="$(parse_jvm_options "$ES_JVM_OPTIONS") $ES_JAVA_OPTS" -declare -a args=("$@") -args=("${args[@]}" --path.conf "$CONF_DIR") - # manual parsing to find out, if process should be detached daemonized=`echo $* | egrep -- '(^-d |-d$| -d |--daemonize$|--daemonize )'` if [ -z "$daemonized" ] ; then - exec "$JAVA" $ES_JAVA_OPTS -Des.path.home="$ES_HOME" -cp "$ES_CLASSPATH" \ - org.elasticsearch.bootstrap.Elasticsearch "${args[@]}" + exec \ + "$JAVA" \ + $ES_JAVA_OPTS \ + -Des.path.home="$ES_HOME" \ + -Des.path.conf="$CONF_DIR" \ + -cp "$ES_CLASSPATH" \ + org.elasticsearch.bootstrap.Elasticsearch \ + "$@" else - exec "$JAVA" $ES_JAVA_OPTS -Des.path.home="$ES_HOME" -cp "$ES_CLASSPATH" \ - org.elasticsearch.bootstrap.Elasticsearch "${args[@]}" <&- & + exec \ + "$JAVA" \ + $ES_JAVA_OPTS \ + -Des.path.home="$ES_HOME" \ + -Des.path.conf="$CONF_DIR" \ + -cp "$ES_CLASSPATH" \ + org.elasticsearch.bootstrap.Elasticsearch \ + "$@" \ + <&- & retval=$? pid=$! [ $retval -eq 0 ] || exit $retval diff --git a/distribution/src/main/resources/bin/elasticsearch-keystore b/distribution/src/main/resources/bin/elasticsearch-keystore index 943a5db8be9..61d7bb8e5d4 100755 --- a/distribution/src/main/resources/bin/elasticsearch-keystore +++ b/distribution/src/main/resources/bin/elasticsearch-keystore @@ -2,7 +2,11 @@ source "`dirname "$0"`"/elasticsearch-env -declare -a args=("$@") -args=("${args[@]}" --path.conf "$CONF_DIR") - -exec "$JAVA" $ES_JAVA_OPTS -Des.path.home="$ES_HOME" -cp "$ES_CLASSPATH" org.elasticsearch.common.settings.KeyStoreCli "${args[@]}" +exec \ + "$JAVA" \ + $ES_JAVA_OPTS \ + -Des.path.home="$ES_HOME" \ + -Des.path.conf="$CONF_DIR" \ + -cp "$ES_CLASSPATH" \ + org.elasticsearch.common.settings.KeyStoreCli \ + "$@" diff --git a/distribution/src/main/resources/bin/elasticsearch-plugin b/distribution/src/main/resources/bin/elasticsearch-plugin index 764349064d9..4b48964f97d 100755 --- a/distribution/src/main/resources/bin/elasticsearch-plugin +++ b/distribution/src/main/resources/bin/elasticsearch-plugin @@ -2,7 +2,11 @@ source "`dirname "$0"`"/elasticsearch-env -declare -a args=("$@") -args=("${args[@]}" --path.conf "$CONF_DIR") - -exec "$JAVA" $ES_JAVA_OPTS -Des.path.home="$ES_HOME" -cp "$ES_CLASSPATH" org.elasticsearch.plugins.PluginCli "${args[@]}" +exec \ + "$JAVA" \ + $ES_JAVA_OPTS \ + -Des.path.home="$ES_HOME" \ + -Des.path.conf="$CONF_DIR" \ + -cp "$ES_CLASSPATH" \ + org.elasticsearch.plugins.PluginCli \ + "$@" diff --git a/distribution/src/main/resources/bin/elasticsearch-translog b/distribution/src/main/resources/bin/elasticsearch-translog index db8aad417b4..4326bab8683 100755 --- a/distribution/src/main/resources/bin/elasticsearch-translog +++ b/distribution/src/main/resources/bin/elasticsearch-translog @@ -2,7 +2,11 @@ source "`dirname "$0"`"/elasticsearch-env -declare -a args=("$@") -args=("${args[@]}" --path.conf "$CONF_DIR") - -exec "$JAVA" $ES_JAVA_OPTS -Des.path.home="$ES_HOME" -cp "$ES_CLASSPATH" org.elasticsearch.index.translog.TranslogToolCli "${args[@]}" +exec \ + "$JAVA" \ + $ES_JAVA_OPTS \ + -Des.path.home="$ES_HOME" \ + -Des.path.conf="$CONF_DIR" \ + -cp "$ES_CLASSPATH" \ + org.elasticsearch.index.translog.TranslogToolCli \ + "$@"