Use jvm.options where needed in packaging tests

We have some packaging tests where we use a custom jvm.options file. The
flags we use here are barebones, just enough to exercise that using a
custom jvm.options files actually works. Due to this, we are missing a
Log4j flag that prevents Log4j from trying to use JMX. If Log4j tries to
use JMX, it hits a security manager exception and tries to log
this. This attempt to log happens before we've configured
logging. Previously, Elasticsearch was lenient here so this was treated
as harmless and the test could march on. Now, we fail startup if we
detect an attempt to log before logging is configured so this prevents
Elasticsearch from starting if we do not have jvm.options files in place
that prevent these log messages from being written before logging is
being configured. This commit adds jvm.options files in the places need
to prevent this.
This commit is contained in:
Jason Tedor 2017-04-13 12:00:10 -04:00
parent 5e54c0261a
commit d4947c26ae
4 changed files with 12 additions and 1 deletions

View File

@ -116,6 +116,10 @@ setup() {
chown -R elasticsearch:elasticsearch "$temp" chown -R elasticsearch:elasticsearch "$temp"
echo "-Xms512m" >> "$temp/jvm.options" echo "-Xms512m" >> "$temp/jvm.options"
echo "-Xmx512m" >> "$temp/jvm.options" echo "-Xmx512m" >> "$temp/jvm.options"
# we have to disable Log4j from using JMX lest it will hit a security
# manager exception before we have configured logging; this will fail
# startup since we detect usages of logging before it is configured
echo "-Dlog4j2.disable.jmx=true" >> "$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

View File

@ -147,6 +147,10 @@ setup() {
chown -R elasticsearch:elasticsearch "$temp" chown -R elasticsearch:elasticsearch "$temp"
echo "-Xms512m" >> "$temp/jvm.options" echo "-Xms512m" >> "$temp/jvm.options"
echo "-Xmx512m" >> "$temp/jvm.options" echo "-Xmx512m" >> "$temp/jvm.options"
# we have to disable Log4j from using JMX lest it will hit a security
# manager exception before we have configured logging; this will fail
# startup since we detect usages of logging before it is configured
echo "-Dlog4j2.disable.jmx=true" >> "$temp/jvm.options"
cp $ESENVFILE "$temp/elasticsearch" cp $ESENVFILE "$temp/elasticsearch"
echo "ES_JVM_OPTIONS=\"$temp/jvm.options\"" >> $ESENVFILE echo "ES_JVM_OPTIONS=\"$temp/jvm.options\"" >> $ESENVFILE
echo "ES_JAVA_OPTS=\"-XX:-UseCompressedOops\"" >> $ESENVFILE echo "ES_JAVA_OPTS=\"-XX:-UseCompressedOops\"" >> $ESENVFILE

View File

@ -142,7 +142,7 @@ fi
move_config move_config
CONF_DIR="$ESCONFIG" install_jvm_example CONF_DIR="$ESCONFIG" install_jvm_example
CONF_DIR="$ESCONFIG" start_elasticsearch_service CONF_DIR="$ESCONFIG" ES_JVM_OPTIONS="$ESCONFIG/jvm.options" start_elasticsearch_service
diff <(curl -s localhost:9200/_cat/configured_example | sed 's/ //g') <(echo "foo") diff <(curl -s localhost:9200/_cat/configured_example | sed 's/ //g') <(echo "foo")
stop_elasticsearch_service stop_elasticsearch_service
CONF_DIR="$ESCONFIG" remove_jvm_example CONF_DIR="$ESCONFIG" remove_jvm_example

View File

@ -330,8 +330,10 @@ run_elasticsearch_service() {
if [ ! -z "$CONF_DIR" ] ; then if [ ! -z "$CONF_DIR" ] ; then
if is_dpkg ; then if is_dpkg ; then
echo "CONF_DIR=$CONF_DIR" >> /etc/default/elasticsearch; echo "CONF_DIR=$CONF_DIR" >> /etc/default/elasticsearch;
echo "ES_JVM_OPTIONS=$ES_JVM_OPTIONS" >> /etc/default/elasticsearch;
elif is_rpm; then elif is_rpm; then
echo "CONF_DIR=$CONF_DIR" >> /etc/sysconfig/elasticsearch; echo "CONF_DIR=$CONF_DIR" >> /etc/sysconfig/elasticsearch;
echo "ES_JVM_OPTIONS=$ES_JVM_OPTIONS" >> /etc/sysconfig/elasticsearch
fi fi
fi fi
@ -525,6 +527,7 @@ move_config() {
mv "$oldConfig"/* "$ESCONFIG" mv "$oldConfig"/* "$ESCONFIG"
chown -R elasticsearch:elasticsearch "$ESCONFIG" chown -R elasticsearch:elasticsearch "$ESCONFIG"
assert_file_exist "$ESCONFIG/elasticsearch.yml" assert_file_exist "$ESCONFIG/elasticsearch.yml"
assert_file_exist "$ESCONFIG/jvm.options"
assert_file_exist "$ESCONFIG/log4j2.properties" assert_file_exist "$ESCONFIG/log4j2.properties"
} }