aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2019-03-13 09:58:40 +0100
committerSonarTech <sonartech@sonarsource.com>2019-03-19 20:21:25 +0100
commit90660265e4ee3255cd5680bdcf10bbe854f82f21 (patch)
tree8d38bd9e67e93718dd098f69c2f4121d7f7cf6fd
parent8edde8c99147975908e6bfe3db1a5ba46039b2e4 (diff)
downloadsonarqube-90660265e4ee3255cd5680bdcf10bbe854f82f21.tar.gz
sonarqube-90660265e4ee3255cd5680bdcf10bbe854f82f21.zip
SONAR-11792 workaround ES bug with space in tmp dir path
-rw-r--r--.gitignore1
-rw-r--r--sonar-application/build.gradle8
-rwxr-xr-xsonar-application/src/main/assembly/elasticsearch-patch/bin/elasticsearch79
3 files changed, 87 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 4f13e6683a0..0ca67625b6a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,6 +22,7 @@ out/
# Directories generated on build on Windows
bin/
!sonar-application/src/main/assembly/elasticsearch/**/bin/
+!sonar-application/src/main/assembly/elasticsearch-patch/**/bin/
# npm logs
npm-debug.log*
diff --git a/sonar-application/build.gradle b/sonar-application/build.gradle
index 6832cbf25b0..2d8f5dbbb72 100644
--- a/sonar-application/build.gradle
+++ b/sonar-application/build.gradle
@@ -92,7 +92,9 @@ task zip(type: Zip, dependsOn: [configurations.compile]) {
into("${archiveDir}/") {
from file('src/main/assembly')
- // no windows related binaries are packaged since we start ES on windows directly with java -jar
+ exclude 'elasticsearch-patch'
+ // elasticsearch script will be replaced by patched version below
+ exclude 'elasticsearch/bin/elasticsearch'
exclude 'elasticsearch/bin/elasticsearch.bat'
exclude 'elasticsearch/bin/elasticsearch-env.bat'
exclude 'elasticsearch/bin/elasticsearch-service.bat'
@@ -123,6 +125,10 @@ task zip(type: Zip, dependsOn: [configurations.compile]) {
exclude 'elasticsearch/modules/tribe/**'
exclude 'elasticsearch/modules/x-pack-*/**'
}
+ into("${archiveDir}/elasticsearch/") {
+ from file('src/main/assembly/elasticsearch-patch')
+ include 'bin/elasticsearch'
+ }
// Create the empty dir (plugins) required by elasticsearch
into("${archiveDir}/elasticsearch/") {
from "$buildDir/elasticsearch"
diff --git a/sonar-application/src/main/assembly/elasticsearch-patch/bin/elasticsearch b/sonar-application/src/main/assembly/elasticsearch-patch/bin/elasticsearch
new file mode 100755
index 00000000000..ede3828263f
--- /dev/null
+++ b/sonar-application/src/main/assembly/elasticsearch-patch/bin/elasticsearch
@@ -0,0 +1,79 @@
+#!/bin/bash
+
+# CONTROLLING STARTUP:
+#
+# This script relies on a few environment variables to determine startup
+# behavior, those variables are:
+#
+# ES_PATH_CONF -- Path to config directory
+# ES_JAVA_OPTS -- External Java Opts on top of the defaults set
+#
+# Optionally, exact memory values can be set using the `ES_JAVA_OPTS`. Note that
+# the Xms and Xmx lines in the JVM options file must be commented out. Example
+# values are "512m", and "10g".
+#
+# ES_JAVA_OPTS="-Xms8g -Xmx8g" ./bin/elasticsearch
+
+source "`dirname "$0"`"/elasticsearch-env
+
+ES_JVM_OPTIONS="$ES_PATH_CONF"/jvm.options
+#### SQ WORKAROUND https://github.com/elastic/elasticsearch/issues/39965 ####
+# ES relies on JvmOptionsParser to apply Java version specific options. SQ does not need that because it generates
+# the content of the jvm.options file depending on Java version already.
+#
+# Also, ES accepts extra JVM options specified with ES_JAVA_OPTS env variable. SQ silences this env variable to enforce
+# end users specify ES JVM options with "sonar.search.javaOpts" and "sonar.search.javaAdditionalOpt". Workaround drops
+# supports for ES_JAVA_OPTS as it just make things simpler.
+#
+# Below we read content of file "$ES_JVM_OPTIONS" directly in bash, ignoring comments and empty lines and build
+# a JVM_OPTIONS array. We later use "${JVM_OPTIONS[@]}" instead of $ES_JAVA_OPTS to benefit from built-in escaping of
+# each array value when building the Java command line.
+#
+# Note: "|| [[ "$line" ]]" below is required to support jvm.options file not ending with an empty line
+JVM_OPTIONS=()
+while read -r line || [[ "$line" ]]; do
+ # ignore empty or comment lines
+ if [[ -z "$line" ]] || [[ $line =~ ^#.* ]]; then
+ continue
+ fi
+ JVM_OPTIONS+=("$line")
+done < "$ES_JVM_OPTIONS"
+
+cd "$ES_HOME"
+# manual parsing to find out, if process should be detached
+if ! echo $* | grep -E '(^-d |-d$| -d |--daemonize$|--daemonize )' > /dev/null; then
+ exec \
+ "$JAVA" \
+ "${JVM_OPTIONS[@]}" \
+ -Des.path.home="$ES_HOME" \
+ -Des.path.conf="$ES_PATH_CONF" \
+ -Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
+ -Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
+ -cp "$ES_CLASSPATH" \
+ org.elasticsearch.bootstrap.Elasticsearch \
+ "$@"
+else
+ exec \
+ "$JAVA" \
+ "${JVM_OPTIONS[@]}" \
+ -Des.path.home="$ES_HOME" \
+ -Des.path.conf="$ES_PATH_CONF" \
+ -Des.distribution.flavor="$ES_DISTRIBUTION_FLAVOR" \
+ -Des.distribution.type="$ES_DISTRIBUTION_TYPE" \
+ -cp "$ES_CLASSPATH" \
+ org.elasticsearch.bootstrap.Elasticsearch \
+ "$@" \
+ <&- &
+ retval=$?
+ pid=$!
+ [ $retval -eq 0 ] || exit $retval
+ if [ ! -z "$ES_STARTUP_SLEEP_TIME" ]; then
+ sleep $ES_STARTUP_SLEEP_TIME
+ fi
+ if ! ps -p $pid > /dev/null ; then
+ exit 1
+ fi
+ exit 0
+fi
+
+exit $?