Skip to content

Commit b43ed88

Browse files
authored
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 elastic#21445
1 parent b0f5ea3 commit b43ed88

File tree

4 files changed

+25
-4
lines changed

4 files changed

+25
-4
lines changed

distribution/deb/src/main/packaging/init.d/elasticsearch

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ DAEMON_OPTS="-d -p $PID_FILE -Edefault.path.logs=$LOG_DIR -Edefault.path.data=$D
8484
export ES_JAVA_OPTS
8585
export JAVA_HOME
8686
export ES_INCLUDE
87+
export ES_JVM_OPTIONS
8788

8889
if [ ! -x "$DAEMON" ]; then
8990
echo "The elasticsearch startup script does not exists or it is not executable, tried: $DAEMON"

distribution/rpm/src/main/packaging/init.d/elasticsearch

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ prog="elasticsearch"
6060
pidfile="$PID_DIR/${prog}.pid"
6161

6262
export ES_JAVA_OPTS
63-
export ES_STARTUP_SLEEP_TIME
6463
export JAVA_HOME
6564
export ES_INCLUDE
65+
export ES_JVM_OPTIONS
66+
export ES_STARTUP_SLEEP_TIME
6667

6768
lockfile=/var/lock/subsys/$prog
6869

qa/vagrant/src/test/resources/packaging/scripts/20_tar_package.bats

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ setup() {
110110
local temp=`mktemp -d`
111111
touch "$temp/jvm.options"
112112
chown -R elasticsearch:elasticsearch "$temp"
113-
echo "-Xms264m" >> "$temp/jvm.options"
114-
echo "-Xmx264m" >> "$temp/jvm.options"
113+
echo "-Xms512m" >> "$temp/jvm.options"
114+
echo "-Xmx512m" >> "$temp/jvm.options"
115115
export ES_JVM_OPTIONS="$temp/jvm.options"
116116
export ES_JAVA_OPTS="-XX:-UseCompressedOops"
117117
start_elasticsearch_service
118-
curl -s -XGET localhost:9200/_nodes | fgrep '"heap_init_in_bytes":276824064'
118+
curl -s -XGET localhost:9200/_nodes | fgrep '"heap_init_in_bytes":536870912'
119119
curl -s -XGET localhost:9200/_nodes | fgrep '"using_compressed_ordinary_object_pointers":"false"'
120120
stop_elasticsearch_service
121121
export ES_JVM_OPTIONS=$es_jvm_options

qa/vagrant/src/test/resources/packaging/scripts/70_sysv_initd.bats

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,25 @@ setup() {
134134
[ "$status" -eq 3 ] || [ "$status" -eq 4 ]
135135
}
136136

137+
@test "[INIT.D] start Elasticsearch with custom JVM options" {
138+
local es_java_opts=$ES_JAVA_OPTS
139+
local es_jvm_options=$ES_JVM_OPTIONS
140+
local temp=`mktemp -d`
141+
touch "$temp/jvm.options"
142+
chown -R elasticsearch:elasticsearch "$temp"
143+
echo "-Xms512m" >> "$temp/jvm.options"
144+
echo "-Xmx512m" >> "$temp/jvm.options"
145+
cp /etc/sysconfig/elasticsearch "$temp/elasticsearch"
146+
echo "ES_JVM_OPTIONS=\"$temp/jvm.options\"" >> /etc/sysconfig/elasticsearch
147+
echo "ES_JAVA_OPTS=\"-XX:-UseCompressedOops\"" >> /etc/sysconfig/elasticsearch
148+
service elasticsearch start
149+
wait_for_elasticsearch_status
150+
curl -s -XGET localhost:9200/_nodes | fgrep '"heap_init_in_bytes":536870912'
151+
curl -s -XGET localhost:9200/_nodes | fgrep '"using_compressed_ordinary_object_pointers":"false"'
152+
service elasticsearch stop
153+
cp "$temp/elasticsearch" /etc/sysconfig/elasticsearch
154+
}
155+
137156
# Simulates the behavior of a system restart:
138157
# the PID directory is deleted by the operating system
139158
# but it should not block ES from starting

0 commit comments

Comments
 (0)