Export ES_JVM_OPTIONS for SysV init

The environment variable ES_JVM_OPTIONS allows end-users to specify a
custom location for the jvm.options file. Unfortunately, this
environment variable is not exported from the SysV init scripts. This
commit addresses this issue, and includes a test that ES_JVM_OPTIONS and
ES_JAVA_OPTS work for the SysV init packages.

Relates #21445
This commit is contained in:
Jason Tedor 2016-11-09 17:52:37 -05:00 committed by GitHub
parent b0f5ea3f59
commit b43ed8821f
4 changed files with 25 additions and 4 deletions

View File

@ -84,6 +84,7 @@ DAEMON_OPTS="-d -p $PID_FILE -Edefault.path.logs=$LOG_DIR -Edefault.path.data=$D
export ES_JAVA_OPTS export ES_JAVA_OPTS
export JAVA_HOME export JAVA_HOME
export ES_INCLUDE export ES_INCLUDE
export ES_JVM_OPTIONS
if [ ! -x "$DAEMON" ]; then if [ ! -x "$DAEMON" ]; then
echo "The elasticsearch startup script does not exists or it is not executable, tried: $DAEMON" echo "The elasticsearch startup script does not exists or it is not executable, tried: $DAEMON"

View File

@ -60,9 +60,10 @@ prog="elasticsearch"
pidfile="$PID_DIR/${prog}.pid" pidfile="$PID_DIR/${prog}.pid"
export ES_JAVA_OPTS export ES_JAVA_OPTS
export ES_STARTUP_SLEEP_TIME
export JAVA_HOME export JAVA_HOME
export ES_INCLUDE export ES_INCLUDE
export ES_JVM_OPTIONS
export ES_STARTUP_SLEEP_TIME
lockfile=/var/lock/subsys/$prog lockfile=/var/lock/subsys/$prog

View File

@ -110,12 +110,12 @@ setup() {
local temp=`mktemp -d` local temp=`mktemp -d`
touch "$temp/jvm.options" touch "$temp/jvm.options"
chown -R elasticsearch:elasticsearch "$temp" chown -R elasticsearch:elasticsearch "$temp"
echo "-Xms264m" >> "$temp/jvm.options" echo "-Xms512m" >> "$temp/jvm.options"
echo "-Xmx264m" >> "$temp/jvm.options" echo "-Xmx512m" >> "$temp/jvm.options"
export ES_JVM_OPTIONS="$temp/jvm.options" export ES_JVM_OPTIONS="$temp/jvm.options"
export ES_JAVA_OPTS="-XX:-UseCompressedOops" export ES_JAVA_OPTS="-XX:-UseCompressedOops"
start_elasticsearch_service start_elasticsearch_service
curl -s -XGET localhost:9200/_nodes | fgrep '"heap_init_in_bytes":276824064' curl -s -XGET localhost:9200/_nodes | fgrep '"heap_init_in_bytes":536870912'
curl -s -XGET localhost:9200/_nodes | fgrep '"using_compressed_ordinary_object_pointers":"false"' curl -s -XGET localhost:9200/_nodes | fgrep '"using_compressed_ordinary_object_pointers":"false"'
stop_elasticsearch_service stop_elasticsearch_service
export ES_JVM_OPTIONS=$es_jvm_options export ES_JVM_OPTIONS=$es_jvm_options

View File

@ -134,6 +134,25 @@ setup() {
[ "$status" -eq 3 ] || [ "$status" -eq 4 ] [ "$status" -eq 3 ] || [ "$status" -eq 4 ]
} }
@test "[INIT.D] 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 "-Xms512m" >> "$temp/jvm.options"
echo "-Xmx512m" >> "$temp/jvm.options"
cp /etc/sysconfig/elasticsearch "$temp/elasticsearch"
echo "ES_JVM_OPTIONS=\"$temp/jvm.options\"" >> /etc/sysconfig/elasticsearch
echo "ES_JAVA_OPTS=\"-XX:-UseCompressedOops\"" >> /etc/sysconfig/elasticsearch
service elasticsearch start
wait_for_elasticsearch_status
curl -s -XGET localhost:9200/_nodes | fgrep '"heap_init_in_bytes":536870912'
curl -s -XGET localhost:9200/_nodes | fgrep '"using_compressed_ordinary_object_pointers":"false"'
service elasticsearch stop
cp "$temp/elasticsearch" /etc/sysconfig/elasticsearch
}
# Simulates the behavior of a system restart: # Simulates the behavior of a system restart:
# the PID directory is deleted by the operating system # the PID directory is deleted by the operating system
# but it should not block ES from starting # but it should not block ES from starting