From 3879aa2a98a823a4fba90ea587169adeee1d0ac3 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Mon, 11 Apr 2016 07:15:19 -0400 Subject: [PATCH 01/10] Add JVM options configuration file This commit adds a new configuration file jvm.options to centralize and simplify management of JVM options. This separates the configuration of the JVM from the packaging scripts (bin/elasticsearch*, bin/service.bat, and init.d/elasticsearch) simplifying end-user operational management of custom JVM options. --- distribution/build.gradle | 3 + .../src/main/packaging/init.d/elasticsearch | 19 --- .../src/main/packaging/init.d/elasticsearch | 10 +- .../src/main/packaging/env/elasticsearch | 15 +-- .../src/main/resources/bin/elasticsearch | 34 +++-- .../src/main/resources/bin/elasticsearch.bat | 10 +- .../main/resources/bin/elasticsearch.in.bat | 85 ------------ .../main/resources/bin/elasticsearch.in.sh | 79 ----------- .../src/main/resources/bin/service.bat | 125 +++++++++++++++--- .../main/resources/config/elasticsearch.yml | 5 +- .../src/main/resources/config/jvm.options | 73 ++++++++++ .../migration/migrate_5_0/packaging.asciidoc | 16 +++ .../modules/scripting/security.asciidoc | 7 +- .../setup/install/sysconfig-file.asciidoc | 22 +-- docs/reference/setup/install/windows.asciidoc | 12 -- .../setup/sysconfig/configuring.asciidoc | 17 ++- .../setup/sysconfig/heap_size.asciidoc | 69 +++++++--- docs/reference/setup/sysconfig/swap.asciidoc | 3 +- .../packaging/scripts/20_tar_package.bats | 21 +++ .../packaging/scripts/30_deb_package.bats | 2 + .../packaging/scripts/40_rpm_package.bats | 1 + .../scripts/packaging_test_utils.bash | 2 + 22 files changed, 332 insertions(+), 298 deletions(-) create mode 100644 distribution/src/main/resources/config/jvm.options diff --git a/distribution/build.gradle b/distribution/build.gradle index b9b2784a5b3..0bfa1703d57 100644 --- a/distribution/build.gradle +++ b/distribution/build.gradle @@ -145,6 +145,7 @@ subprojects { configFiles = copySpec { from '../src/main/resources/config' + MavenFilteringHack.filter(it, expansions) } commonFiles = copySpec { @@ -242,6 +243,7 @@ configure(subprojects.findAll { ['deb', 'rpm'].contains(it.name) }) { up to date when the directory is created, which it would by default. And that'll happen when createEtc runs. */ outputs.file "${packagingFiles}/etc/elasticsearch/elasticsearch.yml" + outputs.file "${packagingFiles}/etc/elasticsearch/jvm.options" outputs.file "${packagingFiles}/etc/elasticsearch/logging.yml" } @@ -305,6 +307,7 @@ configure(subprojects.findAll { ['deb', 'rpm'].contains(it.name) }) { } configurationFile '/etc/elasticsearch/elasticsearch.yml' + configurationFile '/etc/elasticsearch/jvm.options' configurationFile '/etc/elasticsearch/logging.yml' into('/etc') { from "${packagingFiles}/etc" diff --git a/distribution/deb/src/main/packaging/init.d/elasticsearch b/distribution/deb/src/main/packaging/init.d/elasticsearch index f241d3c04d3..a8ea9aeff80 100755 --- a/distribution/deb/src/main/packaging/init.d/elasticsearch +++ b/distribution/deb/src/main/packaging/init.d/elasticsearch @@ -46,16 +46,6 @@ ES_GROUP=elasticsearch # Directory where the Elasticsearch binary distribution resides ES_HOME=/usr/share/$NAME -# Heap size defaults to 256m min, 1g max -# Set ES_HEAP_SIZE to 50% of available RAM, but no more than 31g -#ES_HEAP_SIZE=2g - -# Heap new generation -#ES_HEAP_NEWSIZE= - -# max direct memory -#ES_DIRECT_SIZE= - # Additional Java OPTS #ES_JAVA_OPTS= @@ -101,11 +91,7 @@ PID_FILE="$PID_DIR/$NAME.pid" DAEMON=$ES_HOME/bin/elasticsearch 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_NEWSIZE -export ES_DIRECT_SIZE export ES_JAVA_OPTS -export ES_GC_LOG_FILE export JAVA_HOME export ES_INCLUDE @@ -129,11 +115,6 @@ case "$1" in start) checkJava - if [ -n "$MAX_LOCKED_MEMORY" -a -z "$ES_HEAP_SIZE" ]; then - log_failure_msg "MAX_LOCKED_MEMORY is set - ES_HEAP_SIZE must also be set" - exit 1 - fi - log_daemon_msg "Starting $DESC" pid=`pidofproc -p $PID_FILE elasticsearch` diff --git a/distribution/rpm/src/main/packaging/init.d/elasticsearch b/distribution/rpm/src/main/packaging/init.d/elasticsearch index a00980f600d..b2cb8802221 100644 --- a/distribution/rpm/src/main/packaging/init.d/elasticsearch +++ b/distribution/rpm/src/main/packaging/init.d/elasticsearch @@ -59,11 +59,7 @@ exec="$ES_HOME/bin/elasticsearch" prog="elasticsearch" pidfile="$PID_DIR/${prog}.pid" -export ES_HEAP_SIZE -export ES_HEAP_NEWSIZE -export ES_DIRECT_SIZE export ES_JAVA_OPTS -export ES_GC_LOG_FILE export ES_STARTUP_SLEEP_TIME export JAVA_HOME export ES_INCLUDE @@ -91,10 +87,7 @@ checkJava() { start() { checkJava [ -x $exec ] || exit 5 - if [ -n "$MAX_LOCKED_MEMORY" -a -z "$ES_HEAP_SIZE" ]; then - echo "MAX_LOCKED_MEMORY is set - ES_HEAP_SIZE must also be set" - return 7 - fi + if [ -n "$MAX_OPEN_FILES" ]; then ulimit -n $MAX_OPEN_FILES fi @@ -104,7 +97,6 @@ start() { if [ -n "$MAX_MAP_COUNT" -a -f /proc/sys/vm/max_map_count ]; then sysctl -q -w vm.max_map_count=$MAX_MAP_COUNT fi - export ES_GC_LOG_FILE # Ensure that the PID_DIR exists (it is cleaned at OS startup time) if [ -n "$PID_DIR" ] && [ ! -e "$PID_DIR" ]; then diff --git a/distribution/src/main/packaging/env/elasticsearch b/distribution/src/main/packaging/env/elasticsearch index 3662842ba45..9b7f2fd2443 100644 --- a/distribution/src/main/packaging/env/elasticsearch +++ b/distribution/src/main/packaging/env/elasticsearch @@ -20,25 +20,12 @@ # Elasticsearch PID directory #PID_DIR=/var/run/elasticsearch -# Heap size defaults to ${heap.min} min, ${heap.max} max -# Set ES_HEAP_SIZE to 50% of available RAM, but no more than 31g -#ES_HEAP_SIZE=2g - -# Heap new generation -#ES_HEAP_NEWSIZE= - -# Maximum direct memory -#ES_DIRECT_SIZE= - # Additional Java OPTS #ES_JAVA_OPTS= # Configure restart on package upgrade (true, every other setting will lead to not restarting) #ES_RESTART_ON_UPGRADE=true -# Path to the GC log file -#ES_GC_LOG_FILE=/var/log/elasticsearch/gc.log - ################################ # Elasticsearch service ################################ @@ -67,7 +54,7 @@ ES_STARTUP_SLEEP_TIME=5 # The maximum number of bytes of memory that may be locked into RAM # Set to "unlimited" if you use the 'bootstrap.mlockall: true' option -# in elasticsearch.yml (ES_HEAP_SIZE must also be set). +# in elasticsearch.yml. # When using Systemd, the LimitMEMLOCK property must be set # in /usr/lib/systemd/system/elasticsearch.service #MAX_LOCKED_MEMORY=unlimited diff --git a/distribution/src/main/resources/bin/elasticsearch b/distribution/src/main/resources/bin/elasticsearch index 253ee1ee1f5..f964c004858 100755 --- a/distribution/src/main/resources/bin/elasticsearch +++ b/distribution/src/main/resources/bin/elasticsearch @@ -6,14 +6,14 @@ # behavior, those variables are: # # ES_CLASSPATH -- A Java classpath containing everything necessary to run. -# JAVA_OPTS -- Additional arguments to the JVM for heap size, etc +# ES_JVM_OPTIONS -- Path to file containing JVM options # ES_JAVA_OPTS -- External Java Opts on top of the defaults set # +# Optionally, exact memory values can be set using the `ES_JAVA_OPTS`. +# Note that the Xms and Xmx lines in the JVM options file must be +# commented out. Sample format include "512m", and "10g". # -# Optionally, exact memory values can be set using the following values, note, -# they can still be set using the `ES_JAVA_OPTS`. Sample format include "512m", and "10g". -# -# ES_HEAP_SIZE -- Sets both the minimum and maximum memory to allocate (recommended) +# ES_JAVA_OPTS="-Xms8g -Xmx8g" ./bin/elasticsearch # # As a convenience, a fragment of shell is sourced in order to set one or # more of these variables. This so-called `include' can be placed in a @@ -44,6 +44,13 @@ # Check to see if you are trying to run this without building it first. Gradle # will replace the project.name with _something_. + +jvm_options() { + if [ -f "$1" ]; then + echo "$(grep "^-" "$1" | tr '\n' ' ')" + fi +} + if echo '${project.name}' | grep project.name > /dev/null ; then cat >&2 << EOF Error: You must build the project with Maven or download a pre-built package @@ -74,6 +81,17 @@ ES_HOME=`dirname "$SCRIPT"`/.. # make ELASTICSEARCH_HOME absolute ES_HOME=`cd "$ES_HOME"; pwd` +if [ -z "$ES_JVM_OPTIONS" ]; then + for jvm_options in "$ES_HOME"/config/jvm.options \ + /etc/elasticsearch/jvm.options; do + if [ -r "$jvm_options" ]; then + ES_JVM_OPTIONS=$jvm_options + break + fi + done +fi + +ES_JAVA_OPTS="$(jvm_options "$ES_JVM_OPTIONS") $ES_JAVA_OPTS" # If an include wasn't specified in the environment, then search for one... if [ "x$ES_INCLUDE" = "x" ]; then @@ -114,7 +132,7 @@ fi # works around https://bugs.launchpad.net/ubuntu/+source/jayatana/+bug/1441487 if [ "x$JAVA_TOOL_OPTIONS" != "x" ]; then echo "Warning: Ignoring JAVA_TOOL_OPTIONS=$JAVA_TOOL_OPTIONS" - echo "Please pass JVM parameters via JAVA_OPTS instead" + echo "Please pass JVM parameters via ES_JAVA_OPTS instead" unset JAVA_TOOL_OPTIONS fi @@ -126,10 +144,10 @@ export HOSTNAME # manual parsing to find out, if process should be detached daemonized=`echo $* | egrep -- '(^-d |-d$| -d |--daemonize$|--daemonize )'` if [ -z "$daemonized" ] ; then - exec "$JAVA" $JAVA_OPTS $ES_JAVA_OPTS -Des.path.home="$ES_HOME" -cp "$ES_CLASSPATH" \ + exec "$JAVA" $ES_JAVA_OPTS -Des.path.home="$ES_HOME" -cp "$ES_CLASSPATH" \ org.elasticsearch.bootstrap.Elasticsearch "$@" else - exec "$JAVA" $JAVA_OPTS $ES_JAVA_OPTS -Des.path.home="$ES_HOME" -cp "$ES_CLASSPATH" \ + exec "$JAVA" $ES_JAVA_OPTS -Des.path.home="$ES_HOME" -cp "$ES_CLASSPATH" \ org.elasticsearch.bootstrap.Elasticsearch "$@" <&- & retval=$? pid=$! diff --git a/distribution/src/main/resources/bin/elasticsearch.bat b/distribution/src/main/resources/bin/elasticsearch.bat index a2e5d45e1c4..e7058f33cc6 100644 --- a/distribution/src/main/resources/bin/elasticsearch.bat +++ b/distribution/src/main/resources/bin/elasticsearch.bat @@ -35,6 +35,14 @@ FOR /F "usebackq tokens=1* delims= " %%A IN (!params!) DO ( SET HOSTNAME=%COMPUTERNAME% +if "%ES_JVM_OPTIONS%" == "" ( +set ES_JVM_OPTIONS="%~dp0\..\config\jvm.options" +) + +@setlocal +for /F "usebackq delims=" %%a in (`findstr /b \- "%ES_JVM_OPTIONS%"`) do set JVM_OPTIONS=!JVM_OPTIONS! %%a +@endlocal & set ES_JAVA_OPTS=%JVM_OPTIONS% %ES_JAVA_OPTS% + CALL "%~dp0elasticsearch.in.bat" IF ERRORLEVEL 1 ( IF NOT DEFINED nopauseonerror ( @@ -43,6 +51,6 @@ IF ERRORLEVEL 1 ( EXIT /B %ERRORLEVEL% ) -"%JAVA_HOME%\bin\java" %JAVA_OPTS% %ES_JAVA_OPTS% %ES_PARAMS% -cp "%ES_CLASSPATH%" "org.elasticsearch.bootstrap.Elasticsearch" !newparams! +"%JAVA_HOME%\bin\java" %ES_JAVA_OPTS% %ES_PARAMS% -cp "%ES_CLASSPATH%" "org.elasticsearch.bootstrap.Elasticsearch" !newparams! ENDLOCAL diff --git a/distribution/src/main/resources/bin/elasticsearch.in.bat b/distribution/src/main/resources/bin/elasticsearch.in.bat index 537df9d4f9f..d6f1ef308bd 100644 --- a/distribution/src/main/resources/bin/elasticsearch.in.bat +++ b/distribution/src/main/resources/bin/elasticsearch.in.bat @@ -10,91 +10,6 @@ EXIT /B 1 set SCRIPT_DIR=%~dp0 for %%I in ("%SCRIPT_DIR%..") do set ES_HOME=%%~dpfI - -REM ***** JAVA options ***** - -if "%ES_MIN_MEM%" == "" ( -set ES_MIN_MEM=${heap.min} -) - -if "%ES_MAX_MEM%" == "" ( -set ES_MAX_MEM=${heap.max} -) - -if NOT "%ES_HEAP_SIZE%" == "" ( -set ES_MIN_MEM=%ES_HEAP_SIZE% -set ES_MAX_MEM=%ES_HEAP_SIZE% -) - -REM min and max heap sizes should be set to the same value to avoid -REM stop-the-world GC pauses during resize, and so that we can lock the -REM heap in memory on startup to prevent any of it from being swapped -REM out. -set JAVA_OPTS=%JAVA_OPTS% -Xms%ES_MIN_MEM% -Xmx%ES_MAX_MEM% - -REM new generation -if NOT "%ES_HEAP_NEWSIZE%" == "" ( -set JAVA_OPTS=%JAVA_OPTS% -Xmn%ES_HEAP_NEWSIZE% -) - -REM max direct memory -if NOT "%ES_DIRECT_SIZE%" == "" ( -set JAVA_OPTS=%JAVA_OPTS% -XX:MaxDirectMemorySize=%ES_DIRECT_SIZE% -) - -REM set to headless, just in case -set JAVA_OPTS=%JAVA_OPTS% -Djava.awt.headless=true - -REM Force the JVM to use IPv4 stack -if NOT "%ES_USE_IPV4%" == "" ( -set JAVA_OPTS=%JAVA_OPTS% -Djava.net.preferIPv4Stack=true -) - -REM Add gc options. ES_GC_OPTS is unsupported, for internal testing -if "%ES_GC_OPTS%" == "" ( -set ES_GC_OPTS=%ES_GC_OPTS% -XX:+UseParNewGC -set ES_GC_OPTS=%ES_GC_OPTS% -XX:+UseConcMarkSweepGC -set ES_GC_OPTS=%ES_GC_OPTS% -XX:CMSInitiatingOccupancyFraction=75 -set ES_GC_OPTS=%ES_GC_OPTS% -XX:+UseCMSInitiatingOccupancyOnly -REM When running under Java 7 -REM JAVA_OPTS=%JAVA_OPTS% -XX:+UseCondCardMark -) -set JAVA_OPTS=%JAVA_OPTS%%ES_GC_OPTS% - -if "%ES_GC_LOG_FILE%" == "" goto nogclog - -:gclog -set JAVA_OPTS=%JAVA_OPTS% -XX:+PrintGCDetails -set JAVA_OPTS=%JAVA_OPTS% -XX:+PrintGCTimeStamps -set JAVA_OPTS=%JAVA_OPTS% -XX:+PrintGCDateStamps -set JAVA_OPTS=%JAVA_OPTS% -XX:+PrintClassHistogram -set JAVA_OPTS=%JAVA_OPTS% -XX:+PrintTenuringDistribution -set JAVA_OPTS=%JAVA_OPTS% -XX:+PrintGCApplicationStoppedTime -set JAVA_OPTS=%JAVA_OPTS% -Xloggc:%ES_GC_LOG_FILE% -for %%F in ("%ES_GC_LOG_FILE%") do set ES_GC_LOG_FILE_DIRECTORY=%%~dpF -if NOT EXIST "%ES_GC_LOG_FILE_DIRECTORY%\." mkdir "%ES_GC_LOG_FILE_DIRECTORY%" - -:nogclog - -REM Causes the JVM to dump its heap on OutOfMemory. -set JAVA_OPTS=%JAVA_OPTS% -XX:+HeapDumpOnOutOfMemoryError -REM The path to the heap dump location, note directory must exists and have enough -REM space for a full heap dump. -REM JAVA_OPTS=%JAVA_OPTS% -XX:HeapDumpPath=$ES_HOME/logs/heapdump.hprof - -REM Disables explicit GC -set JAVA_OPTS=%JAVA_OPTS% -XX:+DisableExplicitGC - -REM Enable pre-touching of memory pages used by the JVM during hotspot -REM initialization -set JAVA_OPTS=%JAVA_OPTS% -XX:+AlwaysPreTouch - -REM Ensure UTF-8 encoding by default (e.g. filenames) -set JAVA_OPTS=%JAVA_OPTS% -Dfile.encoding=UTF-8 - -REM Use our provided JNA always versus the system one -set JAVA_OPTS=%JAVA_OPTS% -Djna.nosys=true - REM check in case a user was using this mechanism if "%ES_CLASSPATH%" == "" ( set ES_CLASSPATH=!ES_HOME!/lib/elasticsearch-${project.version}.jar;!ES_HOME!/lib/* diff --git a/distribution/src/main/resources/bin/elasticsearch.in.sh b/distribution/src/main/resources/bin/elasticsearch.in.sh index 69d2fc94112..8f1b5566f90 100644 --- a/distribution/src/main/resources/bin/elasticsearch.in.sh +++ b/distribution/src/main/resources/bin/elasticsearch.in.sh @@ -11,82 +11,3 @@ EOF fi ES_CLASSPATH="$ES_HOME/lib/elasticsearch-${project.version}.jar:$ES_HOME/lib/*" - -if [ "x$ES_MIN_MEM" = "x" ]; then - ES_MIN_MEM=${heap.min} -fi -if [ "x$ES_MAX_MEM" = "x" ]; then - ES_MAX_MEM=${heap.max} -fi -if [ "x$ES_HEAP_SIZE" != "x" ]; then - ES_MIN_MEM=$ES_HEAP_SIZE - ES_MAX_MEM=$ES_HEAP_SIZE -fi - -# min and max heap sizes should be set to the same value to avoid -# stop-the-world GC pauses during resize, and so that we can lock the -# heap in memory on startup to prevent any of it from being swapped -# out. -JAVA_OPTS="$JAVA_OPTS -Xms${ES_MIN_MEM}" -JAVA_OPTS="$JAVA_OPTS -Xmx${ES_MAX_MEM}" - -# new generation -if [ "x$ES_HEAP_NEWSIZE" != "x" ]; then - JAVA_OPTS="$JAVA_OPTS -Xmn${ES_HEAP_NEWSIZE}" -fi - -# max direct memory -if [ "x$ES_DIRECT_SIZE" != "x" ]; then - JAVA_OPTS="$JAVA_OPTS -XX:MaxDirectMemorySize=${ES_DIRECT_SIZE}" -fi - -# set to headless, just in case -JAVA_OPTS="$JAVA_OPTS -Djava.awt.headless=true" - -# Force the JVM to use IPv4 stack -if [ "x$ES_USE_IPV4" != "x" ]; then - JAVA_OPTS="$JAVA_OPTS -Djava.net.preferIPv4Stack=true" -fi - -# Add gc options. ES_GC_OPTS is unsupported, for internal testing -if [ "x$ES_GC_OPTS" = "x" ]; then - ES_GC_OPTS="$ES_GC_OPTS -XX:+UseParNewGC" - ES_GC_OPTS="$ES_GC_OPTS -XX:+UseConcMarkSweepGC" - ES_GC_OPTS="$ES_GC_OPTS -XX:CMSInitiatingOccupancyFraction=75" - ES_GC_OPTS="$ES_GC_OPTS -XX:+UseCMSInitiatingOccupancyOnly" -fi - -JAVA_OPTS="$JAVA_OPTS $ES_GC_OPTS" - -# GC logging options -if [ -n "$ES_GC_LOG_FILE" ]; then - JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCDetails" - JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCTimeStamps" - JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCDateStamps" - JAVA_OPTS="$JAVA_OPTS -XX:+PrintClassHistogram" - JAVA_OPTS="$JAVA_OPTS -XX:+PrintTenuringDistribution" - JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCApplicationStoppedTime" - JAVA_OPTS="$JAVA_OPTS -Xloggc:$ES_GC_LOG_FILE" - - # Ensure that the directory for the log file exists: the JVM will not create it. - mkdir -p "`dirname \"$ES_GC_LOG_FILE\"`" -fi - -# Causes the JVM to dump its heap on OutOfMemory. -JAVA_OPTS="$JAVA_OPTS -XX:+HeapDumpOnOutOfMemoryError" -# The path to the heap dump location, note directory must exists and have enough -# space for a full heap dump. -#JAVA_OPTS="$JAVA_OPTS -XX:HeapDumpPath=$ES_HOME/logs/heapdump.hprof" - -# Disables explicit GC -JAVA_OPTS="$JAVA_OPTS -XX:+DisableExplicitGC" - -# Enable pre-touching of memory pages used by the JVM during hotspot -# initialization -JAVA_OPTS="$JAVA_OPTS -XX:+AlwaysPreTouch" - -# Ensure UTF-8 encoding by default (e.g. filenames) -JAVA_OPTS="$JAVA_OPTS -Dfile.encoding=UTF-8" - -# Use our provided JNA always versus the system one -JAVA_OPTS="$JAVA_OPTS -Djna.nosys=true" diff --git a/distribution/src/main/resources/bin/service.bat b/distribution/src/main/resources/bin/service.bat index a8b8731cb59..208a31ce799 100644 --- a/distribution/src/main/resources/bin/service.bat +++ b/distribution/src/main/resources/bin/service.bat @@ -131,34 +131,92 @@ if exist "%JAVA_HOME%"\bin\client\jvm.dll ( ) :foundJVM -if "%ES_MIN_MEM%" == "" set ES_MIN_MEM=${heap.min} -if "%ES_MAX_MEM%" == "" set ES_MAX_MEM=${heap.max} +if "%ES_JVM_OPTIONS%" == "" ( +set ES_JVM_OPTIONS="%ES_HOME%\config\jvm.options" +) -if NOT "%ES_HEAP_SIZE%" == "" set ES_MIN_MEM=%ES_HEAP_SIZE% -if NOT "%ES_HEAP_SIZE%" == "" set ES_MAX_MEM=%ES_HEAP_SIZE% +if not "%ES_JAVA_OPTS%" == "" set ES_JAVA_OPTS=%ES_JAVA_OPTS: =;% -call:convertxm %ES_MIN_MEM% JVM_XMS -call:convertxm %ES_MAX_MEM% JVM_XMX +@setlocal +for /F "usebackq delims=" %%a in (`findstr /b \- "%ES_JVM_OPTIONS%"`) do set JVM_OPTIONS=!JVM_OPTIONS!%%a; +@endlocal & set ES_JAVA_OPTS=%JVM_OPTIONS%%ES_JAVA_OPTS% -REM java_opts might be empty - init to avoid tripping commons daemon (if the command starts with ;) -if "%JAVA_OPTS%" == "" set JAVA_OPTS=-XX:+UseParNewGC +if "%ES_JAVA_OPTS:~-1%"==";" set ES_JAVA_OPTS=%ES_JAVA_OPTS:~0,-1% + +@setlocal EnableDelayedExpansion +for %%a in ("%ES_JAVA_OPTS:;=","%") do ( + set var=%%a + if "!var:~1,4!" == "-Xms" ( + if not "!JVM_MS!" == "" ( + echo duplicate min heap size settings found + goto:eof + ) + set XMS=!var:~5,-1! + call:convertxm !XMS! JVM_MS + ) + if "!var:~1,16!" == "-XX:MinHeapSize=" ( + if not "!JVM_MS!" == "" ( + echo duplicate min heap size settings found + goto:eof + ) + set XMS=!var:~17,-1! + call:convertxm !XMS! JVM_MS + ) + if "!var:~1,4!" == "-Xmx" ( + if not "!JVM_MX!" == "" ( + echo duplicate max heap size settings found + goto:eof + ) + set XMX=!var:~5,-1! + call:convertxm !XMX! JVM_MX + ) + if "!var:~1,16!" == "-XX:MaxHeapSize=" ( + if not "!JVM_MX!" == "" ( + echo duplicate max heap size settings found + goto:eof + ) + set XMX=!var:~17,-1! + call:convertxm !XMX! JVM_MX + ) + if "!var:~1,4!" == "-Xss" ( + if not "!JVM_SS!" == "" ( + echo duplicate thread stack size settings found + exit 1 + ) + set XSS=!var:~5,-1! + call:convertxk !XSS! JVM_SS + ) + if "!var:~1,20!" == "-XX:ThreadStackSize=" ( + if not "!JVM_SS!" == "" ( + echo duplicate thread stack size settings found + goto:eof + ) + set XSS=!var:~21,-1! + call:convertxk !XSS! JVM_SS + ) +) +@endlocal & set JVM_MS=%JVM_MS% & set JVM_MX=%JVM_MX% & set JVM_SS=%JVM_SS% + +if "%JVM_MS%" == "" ( + echo minimum heap size not set; configure via %ES_JVM_OPTIONS% or ES_JAVA_OPTS + goto:eof +) +if "%JVM_MX%" == "" ( + echo maximum heap size not set; configure via %ES_JVM_OPTIONS% or ES_JAVA_OPTS + goto:eof +) +if "%JVM_SS%" == "" ( + echo thread stack size not set; configure via %ES_JVM_OPTIONS% or ES_JAVA_OPTS + goto:eof +) CALL "%ES_HOME%\bin\elasticsearch.in.bat" - -rem thread stack size -set JVM_SS=256 - if "%DATA_DIR%" == "" set DATA_DIR=%ES_HOME%\data if "%CONF_DIR%" == "" set CONF_DIR=%ES_HOME%\config 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: =;% - -if not "%ES_JAVA_OPTS%" == "" set JVM_ES_JAVA_OPTS=%ES_JAVA_OPTS: =#% -if not "%ES_JAVA_OPTS%" == "" set JVM_OPTS=%JVM_OPTS%;%JVM_ES_JAVA_OPTS% - if "%ES_START_TYPE%" == "" set ES_START_TYPE=manual if "%ES_STOP_TIMEOUT%" == "" set ES_STOP_TIMEOUT=0 @@ -171,8 +229,7 @@ if not "%SERVICE_USERNAME%" == "" ( ) ) -"%EXECUTABLE%" //IS//%SERVICE_ID% --Startup %ES_START_TYPE% --StopTimeout %ES_STOP_TIMEOUT% --StartClass org.elasticsearch.bootstrap.Elasticsearch --StopClass org.elasticsearch.bootstrap.Elasticsearch --StartMethod main --StopMethod close --Classpath "%ES_CLASSPATH%" --JvmSs %JVM_SS% --JvmMs %JVM_XMS% --JvmMx %JVM_XMX% --JvmOptions %JVM_OPTS% ++JvmOptions %ES_PARAMS% %LOG_OPTS% --PidFile "%SERVICE_ID%.pid" --DisplayName "%SERVICE_DISPLAY_NAME%" --Description "%SERVICE_DESCRIPTION%" --Jvm "%%JAVA_HOME%%%JVM_DLL%" --StartMode jvm --StopMode jvm --StartPath "%ES_HOME%" %SERVICE_PARAMS% - +"%EXECUTABLE%" //IS//%SERVICE_ID% --Startup %ES_START_TYPE% --StopTimeout %ES_STOP_TIMEOUT% --StartClass org.elasticsearch.bootstrap.Elasticsearch --StopClass org.elasticsearch.bootstrap.Elasticsearch --StartMethod main --StopMethod close --Classpath "%ES_CLASSPATH%" --JvmMs %JVM_MS% --JvmMx %JVM_MX% --JvmSs %JVM_SS% --JvmOptions %ES_JAVA_OPTS% ++JvmOptions %ES_PARAMS% %LOG_OPTS% --PidFile "%SERVICE_ID%.pid" --DisplayName "%SERVICE_DISPLAY_NAME%" --Description "%SERVICE_DESCRIPTION%" --Jvm "%%JAVA_HOME%%%JVM_DLL%" --StartMode jvm --StopMode jvm --StartPath "%ES_HOME%" %SERVICE_PARAMS% if not errorlevel 1 goto installed echo Failed installing '%SERVICE_ID%' service @@ -219,6 +276,36 @@ set /a conv=%conv% * 1024 set "%~2=%conv%" goto:eof +:convertxk +set value=%~1 +rem extract last char (unit) +set unit=%value:~-1% +rem assume the unit is specified +set conv=%value:~0,-1% + +if "%unit%" == "k" goto kilo +if "%unit%" == "K" goto kilo +if "%unit%" == "m" goto mega +if "%unit%" == "M" goto mega +if "%unit%" == "g" goto giga +if "%unit%" == "G" goto giga + +rem no unit found, must be bytes; consider the whole value +set conv=%value% +rem convert to KB +set /a conv=%conv% / 1024 +goto kilo +:mega +rem convert to KB +set /a conv=%conv% * 1024 +goto kilo +:giga +rem convert to KB +set /a conv=%conv% * 1024 * 1024 +:kilo +set "%~2=%conv%" +goto:eof + :conffileset echo CONF_FILE setting is no longer supported. elasticsearch.yml must be placed in the config directory and cannot be renamed. goto:eof diff --git a/distribution/src/main/resources/config/elasticsearch.yml b/distribution/src/main/resources/config/elasticsearch.yml index 4b335ce7a19..fe103052218 100644 --- a/distribution/src/main/resources/config/elasticsearch.yml +++ b/distribution/src/main/resources/config/elasticsearch.yml @@ -42,8 +42,9 @@ # # bootstrap.mlockall: true # -# Make sure that the `ES_HEAP_SIZE` environment variable is set to about half the memory -# available on the system and that the owner of the process is allowed to use this limit. +# Make sure that the heap size is set to about half the memory available +# on the system and that the owner of the process is allowed to use this +# limit. # # Elasticsearch performs poorly when the system is swapping the memory. # diff --git a/distribution/src/main/resources/config/jvm.options b/distribution/src/main/resources/config/jvm.options new file mode 100644 index 00000000000..691d681c05e --- /dev/null +++ b/distribution/src/main/resources/config/jvm.options @@ -0,0 +1,73 @@ +### configuration + +## basic + +# set to headless, just in case +-Djava.awt.headless=true + +# ensure UTF-8 encoding by default (e.g. filenames) +-Dfile.encoding=UTF-8 + +# use our provided JNA always versus the system one +-Djna.nosys=true + +## networking + +# force the JVM to use the IPv4 stack +#-Djava.net.preferIPv4Stack=true + +### memory + +## heap configuration + +# minimum size of total heap space +-Xms${heap.min} + +# maximum size of total heap space +# it is recommended to set the minimum size and maximum size equal to +# each other to prevent pauses upon resize, and so that memory locking +# will lock the entire heap in physical memory +-Xmx${heap.max} + +# size of young generation heap space +#-Xmn${new.size} + +# maximum size of NIO direct-buffer allocations +#-XX:MaxDirectMemorySize${max.direct.memory.size} + +## CMS configuration +-XX:+UseParNewGC +-XX:+UseConcMarkSweepGC +-XX:CMSInitiatingOccupancyFraction=75 +-XX:+UseCMSInitiatingOccupancyOnly + +## optimizations + +# disable calls to System#gc +-XX:+DisableExplicitGC + +# pre-touch memory pages used by the JVM during initialization +-XX:+AlwaysPreTouch + +## heap dumps + +# generate a heap dump when an allocation from the Java heap fails +# heap dumps are created in the working directory of the JVM +-XX:+HeapDumpOnOutOfMemoryError + +# specify an alternative path for heap dumps +# ensure the directory exists and has sufficient space +#-XX:HeapDumpPath=${heap.dump.path} + +## GC logging + +#-XX:+PrintGCDetails +#-XX:+PrintGCTimeStamps +#-XX:+PrintGCDateStamps +#-XX:+PrintClassHistogram +#-XX:+PrintTenuringDistribution +#-XX:+PrintGCApplicationStoppedTime + +# log GC status to a file with time stamps +# ensure the directory exists +#-Xloggc:${loggc} diff --git a/docs/reference/migration/migrate_5_0/packaging.asciidoc b/docs/reference/migration/migrate_5_0/packaging.asciidoc index 9be2d4accac..c714ef163e1 100644 --- a/docs/reference/migration/migrate_5_0/packaging.asciidoc +++ b/docs/reference/migration/migrate_5_0/packaging.asciidoc @@ -21,4 +21,20 @@ a memory page during GC time. This will increase the startup time of Elasticsearch as well as increasing the initial resident memory usage of the Java process. +==== JVM options + +Arguments to the Java Virtual Machine have been centralized and moved +to a new configuration file jvm.options. This centralization allows for +simpler end-user management of JVM options. + +This migration removes all previous mechanisms of setting JVM options +via the environment variables `ES_MIN_MEM`, `ES_MAX_MEM`, +`ES_HEAP_SIZE`, `ES_HEAP_NEWSIZE`, `ES_DIRECT_SIZE`, `ES_USE_IPV4`, +`ES_GC_OPTS`, `ES_GC_LOG_FILE`, and `JAVA_OPTS`. + +The default location for this file is in config/jvm.options if installing +from the tar or zip distributions, and /etc/elasticsearch/jvm.options if installing +from the Debian or RPM packages. You can specify an alternative location by setting +the environment variable `ES_JVM_OPTIONS` to the path to the file. + diff --git a/docs/reference/modules/scripting/security.asciidoc b/docs/reference/modules/scripting/security.asciidoc index e84289bf1d9..3c9144984d5 100644 --- a/docs/reference/modules/scripting/security.asciidoc +++ b/docs/reference/modules/scripting/security.asciidoc @@ -99,12 +99,13 @@ The classloader whitelist can be customised by tweaking the local Java Security Policy either: * system wide: `$JAVA_HOME/lib/security/java.policy`, -* for just the `elasticsearch` user: `/home/elasticsearch/.java.policy`, or -* from a file specified in the `JAVA_OPTS` environment variable with `-Djava.security.policy=someURL`: +* for just the `elasticsearch` user: `/home/elasticsearch/.java.policy` +* by adding a system property to the <> configuration: `-Djava.security.policy=someURL`, or +* via the `ES_JAVA_OPTS` environment variable with `-Djava.security.policy=someURL`: + [source,js] --------------------------------- -export JAVA_OPTS="${JAVA_OPTS} -Djava.security.policy=file:///path/to/my.policy` +export ES_JAVA_OPTS="${ES_JAVA_OPTS} -Djava.security.policy=file:///path/to/my.policy` ./bin/elasticsearch --------------------------------- diff --git a/docs/reference/setup/install/sysconfig-file.asciidoc b/docs/reference/setup/install/sysconfig-file.asciidoc index c7351610153..55aa0532b93 100644 --- a/docs/reference/setup/install/sysconfig-file.asciidoc +++ b/docs/reference/setup/install/sysconfig-file.asciidoc @@ -11,18 +11,6 @@ Set a custom Java path to be used. -`ES_HEAP_SIZE`:: - - The heap size to start with. - -`ES_HEAP_NEWSIZE`:: - - The size of the new generation heap. - -`ES_DIRECT_SIZE`:: - - The maximum size of the direct memory. - `MAX_OPEN_FILES`:: Maximum number of open files, defaults to `65536`. @@ -30,8 +18,7 @@ `MAX_LOCKED_MEMORY`:: Maximum locked memory size. Set to `unlimited if you use the - `bootstrap.mlockall` option in elasticsearch.yml. You must also set - ES_HEAP_SIZE. + `bootstrap.mlockall` option in elasticsearch.yml. `MAX_MAP_COUNT`:: @@ -66,10 +53,3 @@ package manually. The reason for this is to ensure, that upgrades in a cluster do not result in a continuous shard reallocation resulting in high network traffic and reducing the response times of your cluster. - -`ES_GC_LOG_FILE` :: - - The absolute log file path for creating a garbage collection logfile, - which is done by the JVM. Note that this logfile can grow pretty quick and - thus is disabled by default. - diff --git a/docs/reference/setup/install/windows.asciidoc b/docs/reference/setup/install/windows.asciidoc index f2d37a36bc8..8fd8a19ce71 100644 --- a/docs/reference/setup/install/windows.asciidoc +++ b/docs/reference/setup/install/windows.asciidoc @@ -141,18 +141,6 @@ The Elasticsearch service can be configured prior to installation by setting the The installation directory of the desired JVM to run the service under. -`ES_HEAP_SIZE`:: - - The heap size to start with. - -`ES_MIN_MEM`:: - - The initial memory allocation pool for the JVM (`Xms`). Defaults to `256m`, overriden by `%ES_HEAP_SIZE%`. - -`ES_MAX_MEM`:: - - The maxmimum memory allocation pool for the JVM (`Xmx`). Defaults to `1g`, overriden by `%ES_HEAP_SIZE%`. - `LOG_DIR`:: Log directory, defaults to `%ES_HOME%\logs`. diff --git a/docs/reference/setup/sysconfig/configuring.asciidoc b/docs/reference/setup/sysconfig/configuring.asciidoc index 39f62194db4..0f8f0725103 100644 --- a/docs/reference/setup/sysconfig/configuring.asciidoc +++ b/docs/reference/setup/sysconfig/configuring.asciidoc @@ -104,14 +104,23 @@ LimitMEMLOCK=infinity [[es-java-opts]] ==== Setting JVM system properties -Any Java system properties or arguments which should be passed to the JVM -should be specified in the `ES_JAVA_OPTS` environment variable, for instance: +The preferred method of setting Java Virtual Machine options (including +system properties and JVM flags) is via the jvm.options configuration +file. The default location of this file is config/jvm.options (when +installing from the tar or zip distributions) and +/etc/elasticsearch/jvm.options (when installing from the Debian or RPM +packages). This file contains a line-delimited list of JVM arguments, +which must begin with `-`. You can add custom JVM flags to this file and +check this configuration into your version control system. + +An alternative mechanism for setting Java Virtual Machine options is +via the `ES_JAVA_OPTS` environment variable. For instance: [source,sh] --------------------------------- -EXPORT ES_JAVA_OPTS="$ES_JAVA_OPTS -Djava.io.tmpdir=/path/to/temp/dir" +export ES_JAVA_OPTS="$ES_JAVA_OPTS -Djava.io.tmpdir=/path/to/temp/dir" ./bin/elasticsearch --------------------------------- -When using the RPM or Debian packages, ES_JAVA_OPTS can be specified in the +When using the RPM or Debian packages, `ES_JAVA_OPTS` can be specified in the <>. diff --git a/docs/reference/setup/sysconfig/heap_size.asciidoc b/docs/reference/setup/sysconfig/heap_size.asciidoc index dec1dba02e2..d0c94115d31 100644 --- a/docs/reference/setup/sysconfig/heap_size.asciidoc +++ b/docs/reference/setup/sysconfig/heap_size.asciidoc @@ -1,36 +1,65 @@ [[heap-size]] -=== Set JVM heap size with ES_HEAP_SIZE +=== Set JVM heap size via jvm.options In development mode, Elasticsearch tells the JVM to use a heap with a minimum -size of 256MB and a maximum size of 1GB. When moving to production, it is -important to configure the `ES_HEAP_SIZE environment variable to ensure that -Elasticsearch has enough heap available. +size of 256 MB and a maximum size of 1 GB. When moving to production, it is +important to configure heap size to ensure that Elasticsearch has enough +heap available. -Elasticsearch will assign the entire heap specified in `ES_HEAP_SIZE on startup. +Elasticsearch will assign the entire heap specified in <> +via the Xms (minimum heap size) and Xmx (maximum heap size) settings. -The value for this setting depends on the amount of RAM available on your server. A good rule of thumb is: +The value for these setting depends on the amount of RAM available on +your server. Good rules of thumb are: + +* Set the minimum heap size (Xms) and maximum heap size (Xmx) to be + equal to each other. * The more heap available to Elasticsearch, the more memory it can use for - caching. + caching. But note that too much heap can subject you to long garbage + collection pauses. -* Set the `ES_HEAP_SIZE` to no more than 50% of your RAM, to ensure that there - is enough RAM left for kernel file system caches. +* Set Xmx to no more than 50% of your physical RAM, to ensure that there + is enough physical RAM left for kernel file system caches. -* Don’t set `ES_HEAP_SIZE` to more than about 31GB to ensure that the JVM uses - compressed object pointers (compressed-oops). You can verify that you are - under the limit by looking for a line in the logs like the following: +* Don’t set Xmx to above the cutoff that the JVM uses for compressed + object pointers (compressed oops); the exact cutoff varies but is + near 32 GB. You can verify that you are under the limit by looking + for a line in the logs like the following: heap size [1.9gb], compressed ordinary object pointers [true] -Here are examples of how to set the ES_HEAP_SIZE: +* Even better, try to stay below the threshold for zero-based + compressed oops; the exact cutoff varies but 26 GB is safe on most + systems, but can be as large as 30 GB on some system. You can verify + that you are under the limit by starting Elasticsearch with the JVM + options "-XX:+UnlockDiagnosticVMOptions -XX:+PrintCompressedOopsMode" + and looking for a line like the following: + + heap address: 0x000000011be00000, size: 27648 MB, zero based Compressed Oops + + showing that zero-based compressed oops are enabled instead of + + heap address: 0x0000000118400000, size: 28672 MB, Compressed Oops with base: 0x00000001183ff000 + +Here are examples of how to set the heap size via the jvm.options file: + +[source] +------------------ +Xms2g <1> +Xmx2g <2> +------------------ +<1> Set the minimum heap size to 2g. +<2> Set the maximum heap size to 2g. + +It is also possible to set the heap size via an environment variable. +This can be done by commenting out the `Xms` and `Xmx` settings +in the jvm.options file and setting these values via `ES_JAVA_OPTS`: [source,sh] ------------------ -ES_HEAP_SIZE=2g ./bin/elasticsearch <1> -ES_HEAP_SIZE=4000m ./bin/elasticsearch <2> +ES_JAVA_OPTS="-Xms2g -Xmx2g" ./bin/elasticsearch <3> +ES_JAVA_OPTS="-Xmx4000mb -Xmx4000mb" ./bin/elasticsearch <4> ------------------ -<1> Set the min/max heap size to 2GB. -<2> Set the min/max heap size to 4,000MB. - -When using the Debian or RPM package, ES_HEAP_SIZE can be configured in the -<>. +<3> Set the minimum and maximum heap size to 2 GB. +<4> Set the minimum and maximum heap size to 4000 MB. diff --git a/docs/reference/setup/sysconfig/swap.asciidoc b/docs/reference/setup/sysconfig/swap.asciidoc index c40e7cb3e85..f9de8979b5f 100644 --- a/docs/reference/setup/sysconfig/swap.asciidoc +++ b/docs/reference/setup/sysconfig/swap.asciidoc @@ -83,8 +83,7 @@ export ES_JAVA_OPTS="$ES_JAVA_OPTS -Djava.io.tmpdir=/path/to/temp/dir" The second option is to completely disable swap. Usually Elasticsearch is the only service running on a box, and its memory usage is controlled -by the `ES_HEAP_SIZE` environment variable. There should be no need -to have swap enabled. +by the JVM options. There should be no need to have swap enabled. On Linux systems, you can disable swap temporarily by running: `sudo swapoff -a`. To disable it permanently, you will need diff --git a/qa/vagrant/src/test/resources/packaging/scripts/20_tar_package.bats b/qa/vagrant/src/test/resources/packaging/scripts/20_tar_package.bats index f6a9b22ec3b..5be4d2c6c64 100644 --- a/qa/vagrant/src/test/resources/packaging/scripts/20_tar_package.bats +++ b/qa/vagrant/src/test/resources/packaging/scripts/20_tar_package.bats @@ -95,5 +95,26 @@ setup() { start_elasticsearch_service run_elasticsearch_tests stop_elasticsearch_service +} + +@test "[TAR]" start Elasticsearch with custom JVM options { + local es_java_opts=$ES_JAVA_OPTS + local es_jvm_options=$ES_JVM_OPTIONS + local temp=`mktemp -d` + touch "$temp/jvm.options" + chown -R elasticsearch:elasticsearch "$temp" + echo "-Xms264m" >> "$temp/jvm.options" + echo "-Xmx264m" >> "$temp/jvm.options" + export ES_JVM_OPTIONS="$temp/jvm.options" + export ES_JAVA_OPTS="-XX:-UseCompressedOops" + start_elasticsearch_service + curl -s -XGET localhost:9200/_nodes | fgrep '"heap_init_in_bytes":276824064' + curl -s -XGET localhost:9200/_nodes | fgrep '"using_compressed_ordinary_object_pointers":"false"' + stop_elasticsearch_service + export ES_JVM_OPTIONS=$es_jvm_options + export ES_JAVA_OPTS=$es_java_opts +} + +@test "[TAR]" remove tar { rm -rf "/tmp/elasticsearch" } diff --git a/qa/vagrant/src/test/resources/packaging/scripts/30_deb_package.bats b/qa/vagrant/src/test/resources/packaging/scripts/30_deb_package.bats index 048b208105e..b1136c39b9f 100644 --- a/qa/vagrant/src/test/resources/packaging/scripts/30_deb_package.bats +++ b/qa/vagrant/src/test/resources/packaging/scripts/30_deb_package.bats @@ -128,6 +128,7 @@ setup() { # The configuration files are still here assert_file_exist "/etc/elasticsearch" assert_file_exist "/etc/elasticsearch/elasticsearch.yml" + assert_file_exist "/etc/elasticsearch/jvm.options" assert_file_exist "/etc/elasticsearch/logging.yml" # The env file is still here @@ -148,6 +149,7 @@ setup() { # all remaining files are deleted by the purge assert_file_not_exist "/etc/elasticsearch" assert_file_not_exist "/etc/elasticsearch/elasticsearch.yml" + assert_file_not_exist "/etc/elasticsearch/jvm.options" assert_file_not_exist "/etc/elasticsearch/logging.yml" assert_file_not_exist "/etc/default/elasticsearch" diff --git a/qa/vagrant/src/test/resources/packaging/scripts/40_rpm_package.bats b/qa/vagrant/src/test/resources/packaging/scripts/40_rpm_package.bats index d27622ffdda..064439cdd5a 100644 --- a/qa/vagrant/src/test/resources/packaging/scripts/40_rpm_package.bats +++ b/qa/vagrant/src/test/resources/packaging/scripts/40_rpm_package.bats @@ -116,6 +116,7 @@ setup() { assert_file_not_exist "/etc/elasticsearch" assert_file_not_exist "/etc/elasticsearch/elasticsearch.yml" + assert_file_not_exist "/etc/elasticsearch/jvm.options" assert_file_not_exist "/etc/elasticsearch/logging.yml" assert_file_not_exist "/etc/init.d/elasticsearch" diff --git a/qa/vagrant/src/test/resources/packaging/scripts/packaging_test_utils.bash b/qa/vagrant/src/test/resources/packaging/scripts/packaging_test_utils.bash index 133b6e16f1a..198de4dd400 100644 --- a/qa/vagrant/src/test/resources/packaging/scripts/packaging_test_utils.bash +++ b/qa/vagrant/src/test/resources/packaging/scripts/packaging_test_utils.bash @@ -348,6 +348,8 @@ run_elasticsearch_service() { # This line is attempting to emulate the on login behavior of /usr/share/upstart/sessions/jayatana.conf [ -f /usr/share/java/jayatanaag.jar ] && export JAVA_TOOL_OPTIONS="-javaagent:/usr/share/java/jayatanaag.jar" # And now we can start Elasticsearch normally, in the background (-d) and with a pidfile (-p). +export ES_JVM_OPTIONS=$ES_JVM_OPTIONS +export ES_JAVA_OPTS=$ES_JAVA_OPTS $timeoutCommand/tmp/elasticsearch/bin/elasticsearch $background -p /tmp/elasticsearch/elasticsearch.pid $ES_PATH_CONF $commandLineArgs BASH [ "$status" -eq "$expectedStatus" ] From 00033b3da39ecd841d3e7ef8553b90254f8b93a1 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 12 Apr 2016 11:39:33 -0400 Subject: [PATCH 02/10] Fix placement of comment in bin/elasticsearch This commit fixes the placement of a comment in bin/elasticsearch. The comment was made out of place by the addition of a function definition but order is restored. --- distribution/src/main/resources/bin/elasticsearch | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/distribution/src/main/resources/bin/elasticsearch b/distribution/src/main/resources/bin/elasticsearch index f964c004858..f8b2d95c4da 100755 --- a/distribution/src/main/resources/bin/elasticsearch +++ b/distribution/src/main/resources/bin/elasticsearch @@ -45,12 +45,6 @@ # Check to see if you are trying to run this without building it first. Gradle # will replace the project.name with _something_. -jvm_options() { - if [ -f "$1" ]; then - echo "$(grep "^-" "$1" | tr '\n' ' ')" - fi -} - if echo '${project.name}' | grep project.name > /dev/null ; then cat >&2 << EOF Error: You must build the project with Maven or download a pre-built package @@ -60,6 +54,12 @@ EOF exit 1 fi +jvm_options() { + if [ -f "$1" ]; then + echo "$(grep "^-" "$1" | tr '\n' ' ')" + fi +} + CDPATH="" SCRIPT="$0" From 9460289bee2cda9cb91b2f9d6370663f53a00abb Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 12 Apr 2016 11:42:06 -0400 Subject: [PATCH 03/10] Rename function that parses JVM options This commit renames the function that parses JVM options in bin/elasticsearch from jvm_options to parse_jvm_options. The reason for the rename is because a for-loop variable was shadowing the name of this function and changing the function name further clarifies the purpose of the function. --- distribution/src/main/resources/bin/elasticsearch | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/distribution/src/main/resources/bin/elasticsearch b/distribution/src/main/resources/bin/elasticsearch index f8b2d95c4da..0de11ae18fe 100755 --- a/distribution/src/main/resources/bin/elasticsearch +++ b/distribution/src/main/resources/bin/elasticsearch @@ -54,7 +54,7 @@ EOF exit 1 fi -jvm_options() { +parse_jvm_options() { if [ -f "$1" ]; then echo "$(grep "^-" "$1" | tr '\n' ' ')" fi @@ -91,7 +91,7 @@ if [ -z "$ES_JVM_OPTIONS" ]; then done fi -ES_JAVA_OPTS="$(jvm_options "$ES_JVM_OPTIONS") $ES_JAVA_OPTS" +ES_JAVA_OPTS="$(parse_jvm_options "$ES_JVM_OPTIONS") $ES_JAVA_OPTS" # If an include wasn't specified in the environment, then search for one... if [ "x$ES_INCLUDE" = "x" ]; then From 7743c422dbd14bcebdfbe1d253bf2d4e20445689 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 12 Apr 2016 11:51:30 -0400 Subject: [PATCH 04/10] Warn in bin/elasticsearch if JAVA_OPTS is set JAVA_OPTS is not a built-in mechanism for passing options to the JVM but many people think that it is. We do not respect JAVA_OPTS, but this commit adds a warning if it is set in case the end-user thinks that it will affect Elasticsearch. --- distribution/src/main/resources/bin/elasticsearch | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/distribution/src/main/resources/bin/elasticsearch b/distribution/src/main/resources/bin/elasticsearch index 0de11ae18fe..8407697509e 100755 --- a/distribution/src/main/resources/bin/elasticsearch +++ b/distribution/src/main/resources/bin/elasticsearch @@ -136,6 +136,13 @@ if [ "x$JAVA_TOOL_OPTIONS" != "x" ]; then unset JAVA_TOOL_OPTIONS fi +# JAVA_OPTS is not a built-in JVM mechanism but some people think it is +# so let us warn them that we are not observing the value of $JAVA_OPTS +if [ ! -z "JAVA_OPTS" ]; then + echo "Warning: Ignoring JAVA_OPTS=$JAVA_OPTS" + echo "Please pass JVM parameters via ES_JAVA_OPTS instead" +fi + # full hostname passed through cut for portability on systems that do not support hostname -s # export on separate line for shells that do not support combining definition and export HOSTNAME=`hostname | cut -d. -f1` From 2b1c191b121c1e5ecdec329639625bb701beb7b1 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 12 Apr 2016 12:21:40 -0400 Subject: [PATCH 05/10] Add comments to JVM options parsing for Windows This commit adds some comments to the portion of bin/elasticsearch.bat that is responsible for parsing the JVM options. --- distribution/src/main/resources/bin/elasticsearch.bat | 3 +++ 1 file changed, 3 insertions(+) diff --git a/distribution/src/main/resources/bin/elasticsearch.bat b/distribution/src/main/resources/bin/elasticsearch.bat index e7058f33cc6..11febd676d7 100644 --- a/distribution/src/main/resources/bin/elasticsearch.bat +++ b/distribution/src/main/resources/bin/elasticsearch.bat @@ -36,10 +36,13 @@ FOR /F "usebackq tokens=1* delims= " %%A IN (!params!) DO ( SET HOSTNAME=%COMPUTERNAME% if "%ES_JVM_OPTIONS%" == "" ( +rem '0' is the batch file, '~dp' appends the drive and path set ES_JVM_OPTIONS="%~dp0\..\config\jvm.options" ) @setlocal +rem extract the options from the JVM options file %ES_JVM_OPTIONS% +rem such options are the lines beginning with '-', thus "findstr /b" for /F "usebackq delims=" %%a in (`findstr /b \- "%ES_JVM_OPTIONS%"`) do set JVM_OPTIONS=!JVM_OPTIONS! %%a @endlocal & set ES_JAVA_OPTS=%JVM_OPTIONS% %ES_JAVA_OPTS% From d4cf0f021a28544700af543299d878cec8db4438 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 12 Apr 2016 13:13:42 -0400 Subject: [PATCH 06/10] Fail if unsupported environment variables are set This commit adds a hard failure on startup if any unsupported environment variables from older versions of Elasticsearch are still set. --- .../src/main/resources/bin/elasticsearch | 27 +++++++++++++++++++ .../src/main/resources/bin/elasticsearch.bat | 22 +++++++++++++++ .../src/main/resources/bin/service.bat | 22 +++++++++++++++ 3 files changed, 71 insertions(+) diff --git a/distribution/src/main/resources/bin/elasticsearch b/distribution/src/main/resources/bin/elasticsearch index 8407697509e..aa90e7c510d 100755 --- a/distribution/src/main/resources/bin/elasticsearch +++ b/distribution/src/main/resources/bin/elasticsearch @@ -54,6 +54,33 @@ EOF exit 1 fi +# TODO: remove for Elasticsearch 6.x +unsupported_environment_variable() { + if [ ! -z "$1" ]; then + echo "$2=$1" + fi +} + +if [[ !(-z "$ES_MIN_MEM" && + -z "$ES_MAX_MEM" && + -z "$ES_HEAP_SIZE" && + -z "$ES_HEAP_NEWSIZE" && + -z "$ES_DIRECT_SIZE" && + -z "$ES_USE_IPV4" && + -z "$ES_GC_OPTS") ]]; then + echo "Error: encountered environment variables that are no longer supported" + echo "Use jvm.options or ES_JAVA_OPTS to configure the JVM" + unsupported_environment_variable "$ES_MIN_MEM" ES_MIN_MEM + unsupported_environment_variable "$ES_MAX_MEM" ES_MAX_MEM + unsupported_environment_variable "$ES_HEAP_SIZE" ES_HEAP_SIZE + unsupported_environment_variable "$ES_HEAP_NEWSIZE" ES_HEAP_NEWSIZE + unsupported_environment_variable "$ES_DIRECT_SIZE" ES_DIRECT_SIZE + unsupported_environment_variable "$ES_USE_IPV4" ES_USE_IPV4 + unsupported_environment_variable "$ES_GC_OPTS" ES_GC_OPTS + exit 1 +fi +# end TODO: remove for Elasticsearch 6.x + parse_jvm_options() { if [ -f "$1" ]; then echo "$(grep "^-" "$1" | tr '\n' ' ')" diff --git a/distribution/src/main/resources/bin/elasticsearch.bat b/distribution/src/main/resources/bin/elasticsearch.bat index 11febd676d7..e8683186e0f 100644 --- a/distribution/src/main/resources/bin/elasticsearch.bat +++ b/distribution/src/main/resources/bin/elasticsearch.bat @@ -5,6 +5,28 @@ TITLE Elasticsearch ${project.version} SET params='%*' +rem TODO: remove for Elasticsearch 6.x +if not "%ES_MIN_MEM%" == "" set bad_env_var=1 +if not "%ES_MAX_MEM%" == "" set bad_env_var=1 +if not "%ES_HEAP_SIZE%" == "" set bad_env_var=1 +if not "%ES_HEAP_NEWSIZE%" == "" set bad_env_var=1 +if not "%ES_DIRECT_SIZE%" == "" set bad_env_var=1 +if not "%ES_USE_IPV4%" == "" set bad_env_var=1 +if not "%ES_GC_OPTS%" == "" set bad_env_var=1 +if %bad_env_var% == 1 ( + echo Error: encountered environment variables that are no longer supported + echo Use jvm.options or ES_JAVA_OPTS to configure the JVM + if not "%ES_MIN_MEM%" == "" echo ES_MIN_MEM=%ES_MIN_MEM% + if not "%ES_MAX_MEM%" == "" echo ES_MAX_MEM=%ES_MAX_MEM% + if not "%ES_HEAP_SIZE%" == "" echo ES_HEAP_SIZE=%ES_HEAP_SIZE% + if not "%ES_HEAP_NEWSIZE%" == "" echo ES_HEAP_NEWSIZE=%ES_HEAP_NEWSIZE% + if not "%ES_DIRECT_SIZE%" == "" echo ES_DIRECT_SIZE=%ES_DIRECT_SIZE% + if not "%ES_USE_IPV4%" == "" echo ES_USE_IPV4=%ES_USE_IPV4% + if not "%ES_GC_OPTS%" == "" echo ES_GC_OPTS=%ES_GC_OPTS% + exit /b 1 +) +rem end TODO: remove for Elasticsearch 6.x + :loop FOR /F "usebackq tokens=1* delims= " %%A IN (!params!) DO ( SET current=%%A diff --git a/distribution/src/main/resources/bin/service.bat b/distribution/src/main/resources/bin/service.bat index 208a31ce799..a6f9988de27 100644 --- a/distribution/src/main/resources/bin/service.bat +++ b/distribution/src/main/resources/bin/service.bat @@ -3,6 +3,28 @@ SETLOCAL enabledelayedexpansion TITLE Elasticsearch Service ${project.version} +rem TODO: remove for Elasticsearch 6.x +if not "%ES_MIN_MEM%" == "" set bad_env_var=1 +if not "%ES_MAX_MEM%" == "" set bad_env_var=1 +if not "%ES_HEAP_SIZE%" == "" set bad_env_var=1 +if not "%ES_HEAP_NEWSIZE%" == "" set bad_env_var=1 +if not "%ES_DIRECT_SIZE%" == "" set bad_env_var=1 +if not "%ES_USE_IPV4%" == "" set bad_env_var=1 +if not "%ES_GC_OPTS%" == "" set bad_env_var=1 +if %bad_env_var% == 1 ( + echo Error: encountered environment variables that are no longer supported + echo Use jvm.options or ES_JAVA_OPTS to configure the JVM + if not "%ES_MIN_MEM%" == "" echo ES_MIN_MEM=%ES_MIN_MEM% + if not "%ES_MAX_MEM%" == "" echo ES_MAX_MEM=%ES_MAX_MEM% + if not "%ES_HEAP_SIZE%" == "" echo ES_HEAP_SIZE=%ES_HEAP_SIZE% + if not "%ES_HEAP_NEWSIZE%" == "" echo ES_HEAP_NEWSIZE=%ES_HEAP_NEWSIZE% + if not "%ES_DIRECT_SIZE%" == "" echo ES_DIRECT_SIZE=%ES_DIRECT_SIZE% + if not "%ES_USE_IPV4%" == "" echo ES_USE_IPV4=%ES_USE_IPV4% + if not "%ES_GC_OPTS%" == "" echo ES_GC_OPTS=%ES_GC_OPTS% + exit /b 1 +) +rem end TODO: remove for Elasticsearch 6.x + if NOT DEFINED JAVA_HOME goto err if not "%CONF_FILE%" == "" goto conffileset From bdfa063946d4c5f3ab30918b9c628442c21be27c Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 12 Apr 2016 15:14:37 -0400 Subject: [PATCH 07/10] Add migration messages when rejecting env. vars This commit adds migration messages to the startup scripts when rejecting the old unsupported environment variables. --- .../src/main/resources/bin/elasticsearch | 16 ++++++++-------- .../src/main/resources/bin/elasticsearch.bat | 14 +++++++------- distribution/src/main/resources/bin/service.bat | 14 +++++++------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/distribution/src/main/resources/bin/elasticsearch b/distribution/src/main/resources/bin/elasticsearch index aa90e7c510d..76e78603556 100755 --- a/distribution/src/main/resources/bin/elasticsearch +++ b/distribution/src/main/resources/bin/elasticsearch @@ -57,7 +57,7 @@ fi # TODO: remove for Elasticsearch 6.x unsupported_environment_variable() { if [ ! -z "$1" ]; then - echo "$2=$1" + echo "$2=$1: $3" fi } @@ -70,13 +70,13 @@ if [[ !(-z "$ES_MIN_MEM" && -z "$ES_GC_OPTS") ]]; then echo "Error: encountered environment variables that are no longer supported" echo "Use jvm.options or ES_JAVA_OPTS to configure the JVM" - unsupported_environment_variable "$ES_MIN_MEM" ES_MIN_MEM - unsupported_environment_variable "$ES_MAX_MEM" ES_MAX_MEM - unsupported_environment_variable "$ES_HEAP_SIZE" ES_HEAP_SIZE - unsupported_environment_variable "$ES_HEAP_NEWSIZE" ES_HEAP_NEWSIZE - unsupported_environment_variable "$ES_DIRECT_SIZE" ES_DIRECT_SIZE - unsupported_environment_variable "$ES_USE_IPV4" ES_USE_IPV4 - unsupported_environment_variable "$ES_GC_OPTS" ES_GC_OPTS + unsupported_environment_variable "$ES_MIN_MEM" ES_MIN_MEM "set -Xms$ES_MIN_MEM in jvm.options or add \"-Xms$ES_MIN_MEM\" to ES_JAVA_OPTS" + unsupported_environment_variable "$ES_MAX_MEM" ES_MAX_MEM "set -Xms$ES_MAX_MEM in jvm.options or add \"-Xms$ES_MAX_MEM\" to ES_JAVA_OPTS" + unsupported_environment_variable "$ES_HEAP_SIZE" ES_HEAP_SIZE "set -Xms$ES_HEAP_SIZE and -Xmx$ES_HEAP_SIZE in jvm.options or add \"-Xms$ES_HEAP_SIZE -Xmx$ES_HEAP_SIZE\" to ES_JAVA_OPTS" + unsupported_environment_variable "$ES_HEAP_NEWSIZE" ES_HEAP_NEWSIZE "set -Xmn$ES_HEAP_NEWSIZE in jvm.options or add \"-Xmn$ES_HEAP_SIZE\" to ES_JAVA_OPTS" + unsupported_environment_variable "$ES_DIRECT_SIZE" ES_DIRECT_SIZE "set -XX:MaxDirectMemorySize=$ES_DIRECT_SIZE in jvm.options or add \"-XX:MaxDirectMemorySize=$ES_DIRECT_SIZE\" to ES_JAVA_OPTS" + unsupported_environment_variable "$ES_USE_IPV4" ES_USE_IPV4 "set -Djava.net.preferIPv4Stack=true in jvm.options or add \"-Djava.net.preferIPv4Stack=true\" to ES_JAVA_OPTS" + unsupported_environment_variable "$ES_GC_OPTS" ES_GC_OPTS "set ${ES_GC_OPTS// / and } in jvm.options or add \"$ES_GC_OPTS\" to ES_JAVA_OPTS" exit 1 fi # end TODO: remove for Elasticsearch 6.x diff --git a/distribution/src/main/resources/bin/elasticsearch.bat b/distribution/src/main/resources/bin/elasticsearch.bat index e8683186e0f..186661f74bc 100644 --- a/distribution/src/main/resources/bin/elasticsearch.bat +++ b/distribution/src/main/resources/bin/elasticsearch.bat @@ -16,13 +16,13 @@ if not "%ES_GC_OPTS%" == "" set bad_env_var=1 if %bad_env_var% == 1 ( echo Error: encountered environment variables that are no longer supported echo Use jvm.options or ES_JAVA_OPTS to configure the JVM - if not "%ES_MIN_MEM%" == "" echo ES_MIN_MEM=%ES_MIN_MEM% - if not "%ES_MAX_MEM%" == "" echo ES_MAX_MEM=%ES_MAX_MEM% - if not "%ES_HEAP_SIZE%" == "" echo ES_HEAP_SIZE=%ES_HEAP_SIZE% - if not "%ES_HEAP_NEWSIZE%" == "" echo ES_HEAP_NEWSIZE=%ES_HEAP_NEWSIZE% - if not "%ES_DIRECT_SIZE%" == "" echo ES_DIRECT_SIZE=%ES_DIRECT_SIZE% - if not "%ES_USE_IPV4%" == "" echo ES_USE_IPV4=%ES_USE_IPV4% - if not "%ES_GC_OPTS%" == "" echo ES_GC_OPTS=%ES_GC_OPTS% + if not "%ES_MIN_MEM%" == "" echo ES_MIN_MEM=%ES_MIN_MEM%: set -Xms%ES_MIN_MEM% in jvm.options or add "-Xms%ES_MIN_MEM%" to ES_JAVA_OPTS + if not "%ES_MAX_MEM%" == "" echo ES_MAX_MEM=%ES_MAX_MEM%: set -Xms%ES_MAX_MEM% in jvm.options or add "-Xmx%ES_MAX_MEM%" to ES_JAVA_OPTS + if not "%ES_HEAP_SIZE%" == "" echo ES_HEAP_SIZE=%ES_HEAP_SIZE%: set -Xms%ES_HEAP_SIZE% and -Xmx%ES_HEAP_SIZE% in jvm.options or add "-Xms%ES_HEAP_SIZE% -Xmx%ES_HEAP_SIZE%" to ES_JAVA_OPTS + if not "%ES_HEAP_NEWSIZE%" == "" echo ES_HEAP_NEWSIZE=%ES_HEAP_NEWSIZE%: set -Xmn%ES_HEAP_NEWSIZE% in jvm.options or add "-Xmn%ES_HEAP_SIZE%" to ES_JAVA_OPTS + if not "%ES_DIRECT_SIZE%" == "" echo ES_DIRECT_SIZE=%ES_DIRECT_SIZE%: set -XX:MaxDirectMemorySize=%ES_DIRECT_SIZE% in jvm.options or add "-XX:MaxDirectMemorySize=%ES_DIRECT_SIZE%" to ES_JAVA_OPTS + if not "%ES_USE_IPV4%" == "" echo ES_USE_IPV4=%ES_USE_IPV4%: set -Djava.net.preferIPv4Stack=true in jvm.options or add "-Djava.net.preferIPv4Stack=true" to ES_JAVA_OPTS + if not "%ES_GC_OPTS%" == "" echo ES_GC_OPTS=%ES_GC_OPTS%: set %ES_GC_OPTS: = and % in jvm.options or add "%ES_GC_OPTS%" to ES_JAVA_OPTS exit /b 1 ) rem end TODO: remove for Elasticsearch 6.x diff --git a/distribution/src/main/resources/bin/service.bat b/distribution/src/main/resources/bin/service.bat index a6f9988de27..9e167e12bee 100644 --- a/distribution/src/main/resources/bin/service.bat +++ b/distribution/src/main/resources/bin/service.bat @@ -14,13 +14,13 @@ if not "%ES_GC_OPTS%" == "" set bad_env_var=1 if %bad_env_var% == 1 ( echo Error: encountered environment variables that are no longer supported echo Use jvm.options or ES_JAVA_OPTS to configure the JVM - if not "%ES_MIN_MEM%" == "" echo ES_MIN_MEM=%ES_MIN_MEM% - if not "%ES_MAX_MEM%" == "" echo ES_MAX_MEM=%ES_MAX_MEM% - if not "%ES_HEAP_SIZE%" == "" echo ES_HEAP_SIZE=%ES_HEAP_SIZE% - if not "%ES_HEAP_NEWSIZE%" == "" echo ES_HEAP_NEWSIZE=%ES_HEAP_NEWSIZE% - if not "%ES_DIRECT_SIZE%" == "" echo ES_DIRECT_SIZE=%ES_DIRECT_SIZE% - if not "%ES_USE_IPV4%" == "" echo ES_USE_IPV4=%ES_USE_IPV4% - if not "%ES_GC_OPTS%" == "" echo ES_GC_OPTS=%ES_GC_OPTS% + if not "%ES_MIN_MEM%" == "" echo ES_MIN_MEM=%ES_MIN_MEM%: set -Xms%ES_MIN_MEM% in jvm.options or add "-Xms%ES_MIN_MEM%" to ES_JAVA_OPTS + if not "%ES_MAX_MEM%" == "" echo ES_MAX_MEM=%ES_MAX_MEM%: set -Xms%ES_MAX_MEM% in jvm.options or add "-Xmx%ES_MAX_MEM%" to ES_JAVA_OPTS + if not "%ES_HEAP_SIZE%" == "" echo ES_HEAP_SIZE=%ES_HEAP_SIZE%: set -Xms%ES_HEAP_SIZE% and -Xmx%ES_HEAP_SIZE% in jvm.options or add "-Xms%ES_HEAP_SIZE% -Xmx%ES_HEAP_SIZE%" to ES_JAVA_OPTS + if not "%ES_HEAP_NEWSIZE%" == "" echo ES_HEAP_NEWSIZE=%ES_HEAP_NEWSIZE%: set -Xmn%ES_HEAP_NEWSIZE% in jvm.options or add "-Xmn%ES_HEAP_SIZE%" to ES_JAVA_OPTS + if not "%ES_DIRECT_SIZE%" == "" echo ES_DIRECT_SIZE=%ES_DIRECT_SIZE%: set -XX:MaxDirectMemorySize=%ES_DIRECT_SIZE% in jvm.options or add "-XX:MaxDirectMemorySize=%ES_DIRECT_SIZE%" to ES_JAVA_OPTS + if not "%ES_USE_IPV4%" == "" echo ES_USE_IPV4=%ES_USE_IPV4%: set -Djava.net.preferIPv4Stack=true in jvm.options or add "-Djava.net.preferIPv4Stack=true" to ES_JAVA_OPTS + if not "%ES_GC_OPTS%" == "" echo ES_GC_OPTS=%ES_GC_OPTS%: set %ES_GC_OPTS: = and % in jvm.options or add "%ES_GC_OPTS%" to ES_JAVA_OPTS exit /b 1 ) rem end TODO: remove for Elasticsearch 6.x From 27867c729d67b02330f8341523d8397528f41afd Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 12 Apr 2016 21:16:36 -0400 Subject: [PATCH 08/10] Additional handling of ES_GC_LOG_FILE This commit adds handling of the old ES_GC_LOG_FILE environment variable to treat it like the other removed environment variables. --- distribution/deb/src/main/packaging/init.d/elasticsearch | 3 --- distribution/src/main/resources/bin/elasticsearch | 4 +++- distribution/src/main/resources/bin/elasticsearch.bat | 2 ++ distribution/src/main/resources/bin/service.bat | 2 ++ 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/distribution/deb/src/main/packaging/init.d/elasticsearch b/distribution/deb/src/main/packaging/init.d/elasticsearch index a8ea9aeff80..66d1518e783 100755 --- a/distribution/deb/src/main/packaging/init.d/elasticsearch +++ b/distribution/deb/src/main/packaging/init.d/elasticsearch @@ -67,9 +67,6 @@ CONF_DIR=/etc/$NAME # Maximum number of VMA (Virtual Memory Areas) a process can own MAX_MAP_COUNT=262144 -# Path to the GC log file -#ES_GC_LOG_FILE=/var/log/elasticsearch/gc.log - # Elasticsearch PID file directory PID_DIR="/var/run/elasticsearch" diff --git a/distribution/src/main/resources/bin/elasticsearch b/distribution/src/main/resources/bin/elasticsearch index 76e78603556..7a7102977f6 100755 --- a/distribution/src/main/resources/bin/elasticsearch +++ b/distribution/src/main/resources/bin/elasticsearch @@ -67,7 +67,8 @@ if [[ !(-z "$ES_MIN_MEM" && -z "$ES_HEAP_NEWSIZE" && -z "$ES_DIRECT_SIZE" && -z "$ES_USE_IPV4" && - -z "$ES_GC_OPTS") ]]; then + -z "$ES_GC_OPTS" && + -z "$ES_GC_LOG_FILE") ]]; then echo "Error: encountered environment variables that are no longer supported" echo "Use jvm.options or ES_JAVA_OPTS to configure the JVM" unsupported_environment_variable "$ES_MIN_MEM" ES_MIN_MEM "set -Xms$ES_MIN_MEM in jvm.options or add \"-Xms$ES_MIN_MEM\" to ES_JAVA_OPTS" @@ -77,6 +78,7 @@ if [[ !(-z "$ES_MIN_MEM" && unsupported_environment_variable "$ES_DIRECT_SIZE" ES_DIRECT_SIZE "set -XX:MaxDirectMemorySize=$ES_DIRECT_SIZE in jvm.options or add \"-XX:MaxDirectMemorySize=$ES_DIRECT_SIZE\" to ES_JAVA_OPTS" unsupported_environment_variable "$ES_USE_IPV4" ES_USE_IPV4 "set -Djava.net.preferIPv4Stack=true in jvm.options or add \"-Djava.net.preferIPv4Stack=true\" to ES_JAVA_OPTS" unsupported_environment_variable "$ES_GC_OPTS" ES_GC_OPTS "set ${ES_GC_OPTS// / and } in jvm.options or add \"$ES_GC_OPTS\" to ES_JAVA_OPTS" + unsupported_environment_variable "$ES_GC_LOG_FILE" ES_GC_LOG_FILE "set -Xloggc:$ES_GC_LOG_FILE in jvm.options or add \"-Xloggc:$ES_GC_LOG_FILE\" to ES_JAVA_OPTS" exit 1 fi # end TODO: remove for Elasticsearch 6.x diff --git a/distribution/src/main/resources/bin/elasticsearch.bat b/distribution/src/main/resources/bin/elasticsearch.bat index 186661f74bc..e6bcc634452 100644 --- a/distribution/src/main/resources/bin/elasticsearch.bat +++ b/distribution/src/main/resources/bin/elasticsearch.bat @@ -13,6 +13,7 @@ if not "%ES_HEAP_NEWSIZE%" == "" set bad_env_var=1 if not "%ES_DIRECT_SIZE%" == "" set bad_env_var=1 if not "%ES_USE_IPV4%" == "" set bad_env_var=1 if not "%ES_GC_OPTS%" == "" set bad_env_var=1 +if not "%ES_GC_LOG_FILE%" == "" set bad_env_var=1 if %bad_env_var% == 1 ( echo Error: encountered environment variables that are no longer supported echo Use jvm.options or ES_JAVA_OPTS to configure the JVM @@ -23,6 +24,7 @@ if %bad_env_var% == 1 ( if not "%ES_DIRECT_SIZE%" == "" echo ES_DIRECT_SIZE=%ES_DIRECT_SIZE%: set -XX:MaxDirectMemorySize=%ES_DIRECT_SIZE% in jvm.options or add "-XX:MaxDirectMemorySize=%ES_DIRECT_SIZE%" to ES_JAVA_OPTS if not "%ES_USE_IPV4%" == "" echo ES_USE_IPV4=%ES_USE_IPV4%: set -Djava.net.preferIPv4Stack=true in jvm.options or add "-Djava.net.preferIPv4Stack=true" to ES_JAVA_OPTS if not "%ES_GC_OPTS%" == "" echo ES_GC_OPTS=%ES_GC_OPTS%: set %ES_GC_OPTS: = and % in jvm.options or add "%ES_GC_OPTS%" to ES_JAVA_OPTS + if not "%ES_GC_LOG_FILE%" == "" echo ES_GC_LOG_FILE=%ES_GC_LOG_FILE%: set -Xloggc:%ES_GC_LOG_FILE% in jvm.options or add "-Xloggc:%ES_GC_LOG_FILE%" to ES_JAVA_OPTS" exit /b 1 ) rem end TODO: remove for Elasticsearch 6.x diff --git a/distribution/src/main/resources/bin/service.bat b/distribution/src/main/resources/bin/service.bat index 9e167e12bee..2519550f4aa 100644 --- a/distribution/src/main/resources/bin/service.bat +++ b/distribution/src/main/resources/bin/service.bat @@ -11,6 +11,7 @@ if not "%ES_HEAP_NEWSIZE%" == "" set bad_env_var=1 if not "%ES_DIRECT_SIZE%" == "" set bad_env_var=1 if not "%ES_USE_IPV4%" == "" set bad_env_var=1 if not "%ES_GC_OPTS%" == "" set bad_env_var=1 +if not "%ES_GC_LOG_FILE%" == "" set bad_env_var=1 if %bad_env_var% == 1 ( echo Error: encountered environment variables that are no longer supported echo Use jvm.options or ES_JAVA_OPTS to configure the JVM @@ -21,6 +22,7 @@ if %bad_env_var% == 1 ( if not "%ES_DIRECT_SIZE%" == "" echo ES_DIRECT_SIZE=%ES_DIRECT_SIZE%: set -XX:MaxDirectMemorySize=%ES_DIRECT_SIZE% in jvm.options or add "-XX:MaxDirectMemorySize=%ES_DIRECT_SIZE%" to ES_JAVA_OPTS if not "%ES_USE_IPV4%" == "" echo ES_USE_IPV4=%ES_USE_IPV4%: set -Djava.net.preferIPv4Stack=true in jvm.options or add "-Djava.net.preferIPv4Stack=true" to ES_JAVA_OPTS if not "%ES_GC_OPTS%" == "" echo ES_GC_OPTS=%ES_GC_OPTS%: set %ES_GC_OPTS: = and % in jvm.options or add "%ES_GC_OPTS%" to ES_JAVA_OPTS + if not "%ES_GC_LOG_FILE%" == "" echo ES_GC_LOG_FILE=%ES_GC_LOG_FILE%: set -Xloggc:%ES_GC_LOG_FILE% in jvm.options or add "-Xloggc:%ES_GC_LOG_FILE%" to ES_JAVA_OPTS" exit /b 1 ) rem end TODO: remove for Elasticsearch 6.x From 5662a14d220f1769d63a5b4edb580a9b5d10b24d Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 12 Apr 2016 22:19:03 -0400 Subject: [PATCH 09/10] Rewrite if-statement for shell compatibility This commit rewrites an if-statement in bin/elasticsearch for compatibility with some shells (e.g., dash on Ubuntu). --- .../src/main/resources/bin/elasticsearch | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/distribution/src/main/resources/bin/elasticsearch b/distribution/src/main/resources/bin/elasticsearch index 7a7102977f6..8f7b511c497 100755 --- a/distribution/src/main/resources/bin/elasticsearch +++ b/distribution/src/main/resources/bin/elasticsearch @@ -56,19 +56,19 @@ fi # TODO: remove for Elasticsearch 6.x unsupported_environment_variable() { - if [ ! -z "$1" ]; then + if test -n "$1"; then echo "$2=$1: $3" fi } -if [[ !(-z "$ES_MIN_MEM" && - -z "$ES_MAX_MEM" && - -z "$ES_HEAP_SIZE" && - -z "$ES_HEAP_NEWSIZE" && - -z "$ES_DIRECT_SIZE" && - -z "$ES_USE_IPV4" && - -z "$ES_GC_OPTS" && - -z "$ES_GC_LOG_FILE") ]]; then +if test -n "$ES_MIN_MEM" || + test -n "$ES_MAX_MEM" || + test -n "$ES_HEAP_SIZE" || + test -n "$ES_HEAP_NEWSIZE" || + test -n "$ES_DIRECT_SIZE" || + test -n "$ES_USE_IPV4" || + test -n "$ES_GC_OPTS" || + test -n "$ES_GC_LOG_FILE"; then echo "Error: encountered environment variables that are no longer supported" echo "Use jvm.options or ES_JAVA_OPTS to configure the JVM" unsupported_environment_variable "$ES_MIN_MEM" ES_MIN_MEM "set -Xms$ES_MIN_MEM in jvm.options or add \"-Xms$ES_MIN_MEM\" to ES_JAVA_OPTS" From 1224cc8f7aea9112a7ffa2317b8c3c0174c38225 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 12 Apr 2016 22:27:28 -0400 Subject: [PATCH 10/10] Remove unsupported env. var from node spinup This commit removes setting ES_GC_OPTS from NodeInfo.groovy as this environment variable is no longer supported. --- .../main/groovy/org/elasticsearch/gradle/test/NodeInfo.groovy | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/NodeInfo.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/NodeInfo.groovy index f68084c61fe..09a3bc8d616 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/NodeInfo.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/NodeInfo.groovy @@ -130,8 +130,7 @@ class NodeInfo { } env = [ - 'JAVA_HOME' : project.javaHome, - 'ES_GC_OPTS': config.jvmArgs // we pass these with the undocumented gc opts so the argline can set gc, etc + 'JAVA_HOME' : project.javaHome ] args.addAll("-E", "es.node.portsfile=true") env.put('ES_JAVA_OPTS', config.systemProperties.collect { key, value -> "-D${key}=${value}" }.join(" "))