Skip to content

Commit 9da7f0b

Browse files
authored
Ignore _JAVA_OPTIONS (elastic#124843) (elastic#124945)
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.
1 parent 1d7cf24 commit 9da7f0b

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

distribution/src/bin/elasticsearch-env

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,17 @@ else
5555
JAVA_TYPE="bundled JDK"
5656
fi
5757

58-
# do not let JAVA_TOOL_OPTIONS slip in (as the JVM does by default)
58+
# do not let JAVA_TOOL_OPTIONS OR _JAVA_OPTIONS slip in (as the JVM does by default)
5959
if [ ! -z "$JAVA_TOOL_OPTIONS" ]; then
60-
echo "warning: ignoring JAVA_TOOL_OPTIONS=$JAVA_TOOL_OPTIONS"
60+
echo -n "warning: ignoring JAVA_TOOL_OPTIONS=$JAVA_TOOL_OPTIONS; "
61+
echo "pass JVM parameters via ES_JAVA_OPTS"
6162
unset JAVA_TOOL_OPTIONS
6263
fi
64+
if [ ! -z "$_JAVA_OPTIONS" ]; then
65+
echo -n "warning: ignoring _JAVA_OPTIONS=$_JAVA_OPTIONS; "
66+
echo "pass JVM parameters via ES_JAVA_OPTS"
67+
unset _JAVA_OPTIONS
68+
fi
6369

6470
# warn that we are not observing the value of JAVA_HOME
6571
if [ ! -z "$JAVA_HOME" ]; then

distribution/src/bin/elasticsearch-env.bat

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,17 @@ if defined ES_JAVA_HOME (
5858
set JAVA_TYPE=bundled JDK
5959
)
6060

61-
rem do not let JAVA_TOOL_OPTIONS slip in (as the JVM does by default)
61+
rem do not let JAVA_TOOL_OPTIONS or _JAVA_OPTIONS slip in (as the JVM does by default)
6262
if defined JAVA_TOOL_OPTIONS (
63-
echo warning: ignoring JAVA_TOOL_OPTIONS=%JAVA_TOOL_OPTIONS%
63+
(echo|set /p=ignoring JAVA_TOOL_OPTIONS=%JAVA_TOOL_OPTIONS%; )
64+
echo pass JVM parameters via ES_JAVA_OPTS
6465
set JAVA_TOOL_OPTIONS=
6566
)
67+
if defined _JAVA_OPTIONS (
68+
(echo|set /p=ignoring _JAVA_OPTIONS=%_JAVA_OPTIONS%; )
69+
echo pass JVM parameters via ES_JAVA_OPTS
70+
set _JAVA_OPTIONS=
71+
)
6672

6773
rem warn that we are not observing the value of $JAVA_HOME
6874
if defined JAVA_HOME (

docs/changelog/124843.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 124843
2+
summary: Ignore _JAVA_OPTIONS
3+
area: Infra/CLI
4+
type: enhancement
5+
issues: []

0 commit comments

Comments
 (0)