]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11792 workaround ES bug with space in tmp dir path
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 13 Mar 2019 08:58:40 +0000 (09:58 +0100)
committerSonarTech <sonartech@sonarsource.com>
Tue, 19 Mar 2019 19:21:25 +0000 (20:21 +0100)
.gitignore
sonar-application/build.gradle
sonar-application/src/main/assembly/elasticsearch-patch/bin/elasticsearch [new file with mode: 0755]

index 4f13e6683a05a33f66e4f3ad2fcfbca7a2d2de9b..0ca67625b6abb31a690d9b8a34f47656ef49b8eb 100644 (file)
@@ -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*
index 6832cbf25b014676d0eac34834a540ebdca257b2..2d8f5dbbb72069537f25a606feaab9c3865ab726 100644 (file)
@@ -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 (executable)
index 0000000..ede3828
--- /dev/null
@@ -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 $?