From 01b84791792e90db5ee48467ff2b655429db1173 Mon Sep 17 00:00:00 2001 From: Andreas Kohn Date: Fri, 14 Nov 2014 10:33:27 +0100 Subject: [PATCH] Allow configuration of the GC log file via an environment variable Enabling GC logging works now by setting the environment variable ES_GC_LOG_FILE to the full path to the GC log file. Missing directories will be created as needed. The ES_USE_GC_LOGGING environment variable is no longer used. Closes #8471 Closes #8479 --- bin/elasticsearch | 8 ++++---- bin/elasticsearch.in.bat | Bin 2639 -> 2633 bytes bin/elasticsearch.in.sh | 9 ++++++--- docs/reference/setup/as-a-service.asciidoc | 1 + src/deb/default/elasticsearch | 3 +++ src/deb/init.d/elasticsearch | 4 ++++ src/rpm/init.d/elasticsearch | 3 +++ src/rpm/sysconfig/elasticsearch | 3 +++ 8 files changed, 24 insertions(+), 7 deletions(-) diff --git a/bin/elasticsearch b/bin/elasticsearch index 53b282d0400..6f3d9a992f9 100755 --- a/bin/elasticsearch +++ b/bin/elasticsearch @@ -96,7 +96,7 @@ if [ "x$ES_INCLUDE" = "x" ]; then /usr/local/share/elasticsearch/elasticsearch.in.sh \ /opt/elasticsearch/elasticsearch.in.sh \ ~/.elasticsearch.in.sh \ - $ES_HOME/bin/elasticsearch.in.sh \ + "$ES_HOME/bin/elasticsearch.in.sh" \ "`dirname "$0"`"/elasticsearch.in.sh; do if [ -r "$include" ]; then . "$include" @@ -151,13 +151,13 @@ launch_service() # The es-foreground option will tell Elasticsearch not to close stdout/stderr, but it's up to us not to daemonize. if [ "x$daemonized" = "x" ]; then es_parms="$es_parms -Des.foreground=yes" - exec "$JAVA" $JAVA_OPTS $ES_JAVA_OPTS $es_parms -Des.path.home="$ES_HOME" -cp "$ES_CLASSPATH" $props \ + eval exec "$JAVA" $JAVA_OPTS $ES_JAVA_OPTS $es_parms "\"-Des.path.home=$ES_HOME\"" -cp "\"$ES_CLASSPATH\"" $props \ org.elasticsearch.bootstrap.Elasticsearch # exec without running it in the background, makes it replace this shell, we'll never get here... # no need to return something else # Startup Elasticsearch, background it, and write the pid. - exec "$JAVA" $JAVA_OPTS $ES_JAVA_OPTS $es_parms -Des.path.home="$ES_HOME" -cp "$ES_CLASSPATH" $props \ + eval exec "$JAVA" $JAVA_OPTS $ES_JAVA_OPTS $es_parms "\"-Des.path.home=$ES_HOME\"" -cp "\"$ES_CLASSPATH\"" $props \ org.elasticsearch.bootstrap.Elasticsearch <&- & return $? fi @@ -207,7 +207,7 @@ eval set -- "$args" while true; do case $1 in -v) - "$JAVA" $JAVA_OPTS $ES_JAVA_OPTS $es_parms -Des.path.home="$ES_HOME" -cp "$ES_CLASSPATH" $props \ + eval "$JAVA" $JAVA_OPTS $ES_JAVA_OPTS $es_parms "\"-Des.path.home=$ES_HOME\"" -cp "\"$ES_CLASSPATH\"" $props \ org.elasticsearch.Version exit 0 ;; diff --git a/bin/elasticsearch.in.bat b/bin/elasticsearch.in.bat index 567bec6ee7784765a99fa215f710268d5d542e11..5c0819b3c8a746df701d46d22d4d72d14fa1092a 100644 GIT binary patch delta 304 zcmX>va#Cc&Vpd%xRoCEncjtH?fA@GdPajuRB?Vhs1tleg^!$>1g}nUqEd@)e3xOB7I@8t>v6pa$aP^Vpat|{}2TwRoCG7&|ueicjtH?e|L9JKX+9n1zTGMB_)N)7g_a`Gt-Ds zr=}N@nVTA1l9*di%tf3Q6(i@I#NuL)%;J*#^rFOEVzo_fXA>pXRg({~i4&!EA&ZPe fPJViNvK1&iJp6rKRrP`VV*T`Fz0E7w7cv0=^rcs> diff --git a/bin/elasticsearch.in.sh b/bin/elasticsearch.in.sh index 6c28bf62051..99e66d74bff 100644 --- a/bin/elasticsearch.in.sh +++ b/bin/elasticsearch.in.sh @@ -1,6 +1,6 @@ #!/bin/sh -ES_CLASSPATH=$ES_CLASSPATH:$ES_HOME/lib/${project.build.finalName}.jar:$ES_HOME/lib/*:$ES_HOME/lib/sigar/* +ES_CLASSPATH="$ES_CLASSPATH:$ES_HOME/lib/${project.build.finalName}.jar:$ES_HOME/lib/*:$ES_HOME/lib/sigar/*" if [ "x$ES_MIN_MEM" = "x" ]; then ES_MIN_MEM=256m @@ -45,13 +45,16 @@ JAVA_OPTS="$JAVA_OPTS -XX:CMSInitiatingOccupancyFraction=75" JAVA_OPTS="$JAVA_OPTS -XX:+UseCMSInitiatingOccupancyOnly" # GC logging options -if [ "x$ES_USE_GC_LOGGING" != "x" ]; then +if [ -n "$ES_GC_LOG_FILE" ]; then JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCDetails" JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCTimeStamps" JAVA_OPTS="$JAVA_OPTS -XX:+PrintClassHistogram" JAVA_OPTS="$JAVA_OPTS -XX:+PrintTenuringDistribution" JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCApplicationStoppedTime" - JAVA_OPTS="$JAVA_OPTS -Xloggc:/var/log/elasticsearch/gc.log" + 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. diff --git a/docs/reference/setup/as-a-service.asciidoc b/docs/reference/setup/as-a-service.asciidoc index f3127636af7..c75e409c841 100644 --- a/docs/reference/setup/as-a-service.asciidoc +++ b/docs/reference/setup/as-a-service.asciidoc @@ -26,6 +26,7 @@ Each package features a configuration file, which allows you to set the followin `CONF_FILE`:: Path to configuration file, defaults to `/etc/elasticsearch/elasticsearch.yml` `ES_JAVA_OPTS`:: Any additional java options you may want to apply. This may be useful, if you need to set the `node.name` property, but do not want to change the `elasticsearch.yml` configuration file, because it is distributed via a provisioning system like puppet or chef. Example: `ES_JAVA_OPTS="-Des.node.name=search-01"` `RESTART_ON_UPGRADE`:: Configure restart on package upgrade, defaults to `false`. This means you will have to restart your elasticsearch instance after installing a 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. [float] ==== Debian/Ubuntu diff --git a/src/deb/default/elasticsearch b/src/deb/default/elasticsearch index b2aecd87498..00ab1129a02 100644 --- a/src/deb/default/elasticsearch +++ b/src/deb/default/elasticsearch @@ -42,3 +42,6 @@ # Configure restart on package upgrade (true, every other setting will lead to not restarting) #RESTART_ON_UPGRADE=true + +# Path to the GC log file +#ES_GC_LOG_FILE=/var/log/elasticsearch/gc.log diff --git a/src/deb/init.d/elasticsearch b/src/deb/init.d/elasticsearch index 996eed75812..ce2c81dfb8a 100755 --- a/src/deb/init.d/elasticsearch +++ b/src/deb/init.d/elasticsearch @@ -94,6 +94,9 @@ CONF_FILE=$CONF_DIR/elasticsearch.yml # 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 + # End of variables that can be overwritten in $DEFAULT # overwrite settings from default file @@ -110,6 +113,7 @@ export ES_HEAP_SIZE export ES_HEAP_NEWSIZE export ES_DIRECT_SIZE export ES_JAVA_OPTS +export ES_GC_LOG_FILE # Check DAEMON exists test -x $DAEMON || exit 0 diff --git a/src/rpm/init.d/elasticsearch b/src/rpm/init.d/elasticsearch index c63a1eb18d1..330f02273a3 100644 --- a/src/rpm/init.d/elasticsearch +++ b/src/rpm/init.d/elasticsearch @@ -41,6 +41,7 @@ export ES_HEAP_SIZE export ES_HEAP_NEWSIZE export ES_DIRECT_SIZE export ES_JAVA_OPTS +export ES_GC_LOG_FILE export JAVA_HOME lockfile=/var/lock/subsys/$prog @@ -84,6 +85,8 @@ start() { mkdir -p "$WORK_DIR" chown "$ES_USER":"$ES_GROUP" "$WORK_DIR" fi + export ES_GC_LOG_FILE + echo -n $"Starting $prog: " # if not running, start it up here, usually something like "daemon $exec" daemon --user $ES_USER --pidfile $pidfile $exec -p $pidfile -d -Des.default.path.home=$ES_HOME -Des.default.path.logs=$LOG_DIR -Des.default.path.data=$DATA_DIR -Des.default.path.work=$WORK_DIR -Des.default.path.conf=$CONF_DIR diff --git a/src/rpm/sysconfig/elasticsearch b/src/rpm/sysconfig/elasticsearch index f27c497a6b9..7e0776c6231 100644 --- a/src/rpm/sysconfig/elasticsearch +++ b/src/rpm/sysconfig/elasticsearch @@ -44,3 +44,6 @@ ES_USER=elasticsearch # Configure restart on package upgrade (true, every other setting will lead to not restarting) #RESTART_ON_UPGRADE=true + +# Path to the GC log file +#ES_GC_LOG_FILE=/var/log/elasticsearch/gc.log