Browse Source

Ignore _JAVA_OPTIONS (#124843)

The JVM has a couple ways that Java options can be passed. In
Elasticsearch we ignore these common patterns, instead using our own
bespoke mechanisms for setting options (ES_JAVA_OPTS, etc). The primary
reason for this is some systems like Ubuntu setting these options
globally and then affecting Elasticsearch, often in ways that cause
Elasticsearch to fail to start.

This commit ignores _JAVA_OPTIONS, which is a little known environment
variable that the JVM may pick up options from.
Ryan Ernst 7 months ago
parent
commit
aeee44f2a5

+ 8 - 2
distribution/src/bin/elasticsearch-env

@@ -55,11 +55,17 @@ else
   JAVA_TYPE="bundled JDK"
   JAVA_TYPE="bundled JDK"
 fi
 fi
 
 
-# do not let JAVA_TOOL_OPTIONS slip in (as the JVM does by default)
+# do not let JAVA_TOOL_OPTIONS OR _JAVA_OPTIONS slip in (as the JVM does by default)
 if [ ! -z "$JAVA_TOOL_OPTIONS" ]; then
 if [ ! -z "$JAVA_TOOL_OPTIONS" ]; then
-  echo "warning: ignoring JAVA_TOOL_OPTIONS=$JAVA_TOOL_OPTIONS"
+  echo -n "warning: ignoring JAVA_TOOL_OPTIONS=$JAVA_TOOL_OPTIONS; "
+  echo "pass JVM parameters via ES_JAVA_OPTS"
   unset JAVA_TOOL_OPTIONS
   unset JAVA_TOOL_OPTIONS
 fi
 fi
+if [ ! -z "$_JAVA_OPTIONS" ]; then
+  echo -n "warning: ignoring _JAVA_OPTIONS=$_JAVA_OPTIONS; "
+  echo "pass JVM parameters via ES_JAVA_OPTS"
+  unset _JAVA_OPTIONS
+fi
 
 
 # warn that we are not observing the value of JAVA_HOME
 # warn that we are not observing the value of JAVA_HOME
 if [ ! -z "$JAVA_HOME" ]; then
 if [ ! -z "$JAVA_HOME" ]; then

+ 8 - 2
distribution/src/bin/elasticsearch-env.bat

@@ -58,11 +58,17 @@ if defined ES_JAVA_HOME (
   set JAVA_TYPE=bundled JDK
   set JAVA_TYPE=bundled JDK
 )
 )
 
 
-rem do not let JAVA_TOOL_OPTIONS slip in (as the JVM does by default)
+rem do not let JAVA_TOOL_OPTIONS or _JAVA_OPTIONS slip in (as the JVM does by default)
 if defined JAVA_TOOL_OPTIONS (
 if defined JAVA_TOOL_OPTIONS (
-  echo warning: ignoring JAVA_TOOL_OPTIONS=%JAVA_TOOL_OPTIONS%
+  (echo|set /p=ignoring JAVA_TOOL_OPTIONS=%JAVA_TOOL_OPTIONS%; )
+  echo pass JVM parameters via ES_JAVA_OPTS
   set JAVA_TOOL_OPTIONS=
   set JAVA_TOOL_OPTIONS=
 )
 )
+if defined _JAVA_OPTIONS (
+  (echo|set /p=ignoring _JAVA_OPTIONS=%_JAVA_OPTIONS%; )
+  echo pass JVM parameters via ES_JAVA_OPTS
+  set _JAVA_OPTIONS=
+)
 
 
 rem warn that we are not observing the value of $JAVA_HOME
 rem warn that we are not observing the value of $JAVA_HOME
 if defined JAVA_HOME (
 if defined JAVA_HOME (

+ 5 - 0
docs/changelog/124843.yaml

@@ -0,0 +1,5 @@
+pr: 124843
+summary: Ignore _JAVA_OPTIONS
+area: Infra/CLI
+type: enhancement
+issues: []