diff --git a/distribution/src/bin/elasticsearch b/distribution/src/bin/elasticsearch index f8f6ae0b29b0b..237e61b23a2d4 100755 --- a/distribution/src/bin/elasticsearch +++ b/distribution/src/bin/elasticsearch @@ -96,7 +96,7 @@ fi # - second, JVM options are read from jvm.options and jvm.options.d/*.options # - third, JVM options from ES_JAVA_OPTS are applied # - fourth, ergonomic JVM options are applied -ES_JAVA_OPTS=`export ES_TMPDIR; "$JAVA" -cp "$LAUNCHERS_CLASSPATH" org.elasticsearch.tools.launchers.JvmOptionsParser "$ES_PATH_CONF" "$ES_HOME/plugins"` +ES_JAVA_OPTS=`export ES_TMPDIR; "$JAVA" -cp "$LAUNCHERS_CLASSPATH" -Des.distribution.type="$ES_DISTRIBUTION_TYPE" org.elasticsearch.tools.launchers.JvmOptionsParser "$ES_PATH_CONF" "$ES_HOME/plugins"` # Remove enrollment related parameters before passing the arg list to Elasticsearch for i in "${!ARG_LIST[@]}"; do diff --git a/distribution/src/bin/elasticsearch-env b/distribution/src/bin/elasticsearch-env index 01f425fcf39c2..5362a4b613e10 100644 --- a/distribution/src/bin/elasticsearch-env +++ b/distribution/src/bin/elasticsearch-env @@ -91,21 +91,4 @@ ES_PATH_CONF=`cd "$ES_PATH_CONF"; pwd` ES_DISTRIBUTION_TYPE=@es.distribution.type@ -if [[ "$ES_DISTRIBUTION_TYPE" == "docker" ]]; then - - # The virtual file /proc/self/cgroup should list the current cgroup - # membership. For each hierarchy, you can follow the cgroup path from - # this file to the cgroup filesystem (usually /sys/fs/cgroup/) and - # introspect the statistics for the cgroup for the given - # hierarchy. Alas, Docker breaks this by mounting the container - # statistics at the root while leaving the cgroup paths as the actual - # paths. Therefore, Elasticsearch provides a mechanism to override - # reading the cgroup path from /proc/self/cgroup and instead uses the - # cgroup path defined the JVM system property - # es.cgroups.hierarchy.override. Therefore, we set this value here so - # that cgroup statistics are available for the container this process - # will run in. - export ES_JAVA_OPTS="-Des.cgroups.hierarchy.override=/ $ES_JAVA_OPTS" -fi - cd "$ES_HOME" diff --git a/distribution/tools/launchers/src/main/java/org/elasticsearch/tools/launchers/SystemJvmOptions.java b/distribution/tools/launchers/src/main/java/org/elasticsearch/tools/launchers/SystemJvmOptions.java index 00a11fd1d0293..7d0b746493b93 100644 --- a/distribution/tools/launchers/src/main/java/org/elasticsearch/tools/launchers/SystemJvmOptions.java +++ b/distribution/tools/launchers/src/main/java/org/elasticsearch/tools/launchers/SystemJvmOptions.java @@ -61,7 +61,29 @@ static List systemJvmOptions() { * * TODO: either modularlize Elasticsearch so that we can limit the opening of this module, or find an alternative */ - "--add-opens=java.base/java.io=ALL-UNNAMED" + "--add-opens=java.base/java.io=ALL-UNNAMED", + maybeOverrideDockerCgroup() ).stream().filter(e -> e.isEmpty() == false).collect(Collectors.toList()); } + + /* + * The virtual file /proc/self/cgroup should list the current cgroup + * membership. For each hierarchy, you can follow the cgroup path from + * this file to the cgroup filesystem (usually /sys/fs/cgroup/) and + * introspect the statistics for the cgroup for the given + * hierarchy. Alas, Docker breaks this by mounting the container + * statistics at the root while leaving the cgroup paths as the actual + * paths. Therefore, Elasticsearch provides a mechanism to override + * reading the cgroup path from /proc/self/cgroup and instead uses the + * cgroup path defined the JVM system property + * es.cgroups.hierarchy.override. Therefore, we set this value here so + * that cgroup statistics are available for the container this process + * will run in. + */ + private static String maybeOverrideDockerCgroup() { + if ("docker".equals(System.getProperty("es.distribution.type"))) { + return "-Des.cgroups.hierarchy.override=/"; + } + return ""; + } }