From b43ed8821f57b4f01c0c974e9d5c21313c1cab37 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Wed, 9 Nov 2016 17:52:37 -0500 Subject: [PATCH] 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 --- .../src/main/packaging/init.d/elasticsearch | 1 + .../src/main/packaging/init.d/elasticsearch | 3 ++- .../packaging/scripts/20_tar_package.bats | 6 +++--- .../packaging/scripts/70_sysv_initd.bats | 19 +++++++++++++++++++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/distribution/deb/src/main/packaging/init.d/elasticsearch b/distribution/deb/src/main/packaging/init.d/elasticsearch index ae0bd44c291..cf8b5351aec 100755 --- a/distribution/deb/src/main/packaging/init.d/elasticsearch +++ b/distribution/deb/src/main/packaging/init.d/elasticsearch @@ -84,6 +84,7 @@ DAEMON_OPTS="-d -p $PID_FILE -Edefault.path.logs=$LOG_DIR -Edefault.path.data=$D export ES_JAVA_OPTS export JAVA_HOME export ES_INCLUDE +export ES_JVM_OPTIONS if [ ! -x "$DAEMON" ]; then echo "The elasticsearch startup script does not exists or it is not executable, tried: $DAEMON" diff --git a/distribution/rpm/src/main/packaging/init.d/elasticsearch b/distribution/rpm/src/main/packaging/init.d/elasticsearch index 8f1d93dcbdc..f991dc2f928 100644 --- a/distribution/rpm/src/main/packaging/init.d/elasticsearch +++ b/distribution/rpm/src/main/packaging/init.d/elasticsearch @@ -60,9 +60,10 @@ prog="elasticsearch" pidfile="$PID_DIR/${prog}.pid" export ES_JAVA_OPTS -export ES_STARTUP_SLEEP_TIME export JAVA_HOME export ES_INCLUDE +export ES_JVM_OPTIONS +export ES_STARTUP_SLEEP_TIME lockfile=/var/lock/subsys/$prog 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 83c12f960e5..9712febc760 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 @@ -110,12 +110,12 @@ setup() { local temp=`mktemp -d` touch "$temp/jvm.options" chown -R elasticsearch:elasticsearch "$temp" - echo "-Xms264m" >> "$temp/jvm.options" - echo "-Xmx264m" >> "$temp/jvm.options" + echo "-Xms512m" >> "$temp/jvm.options" + echo "-Xmx512m" >> "$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 '"heap_init_in_bytes":536870912' curl -s -XGET localhost:9200/_nodes | fgrep '"using_compressed_ordinary_object_pointers":"false"' stop_elasticsearch_service export ES_JVM_OPTIONS=$es_jvm_options diff --git a/qa/vagrant/src/test/resources/packaging/scripts/70_sysv_initd.bats b/qa/vagrant/src/test/resources/packaging/scripts/70_sysv_initd.bats index fa96882f914..c394dfa40f3 100644 --- a/qa/vagrant/src/test/resources/packaging/scripts/70_sysv_initd.bats +++ b/qa/vagrant/src/test/resources/packaging/scripts/70_sysv_initd.bats @@ -134,6 +134,25 @@ setup() { [ "$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: # the PID directory is deleted by the operating system # but it should not block ES from starting