]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10690 start.sh, stop.sh & logs.sh support SQ editions
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 24 May 2018 14:00:06 +0000 (16:00 +0200)
committerSonarTech <sonartech@sonarsource.com>
Tue, 12 Jun 2018 18:20:59 +0000 (20:20 +0200)
scripts/editions.sh [new file with mode: 0755]
scripts/logs.sh
scripts/start.sh
scripts/stop.sh [new file with mode: 0755]
sonar-application/build.gradle
stop.sh [changed from file to symlink]

diff --git a/scripts/editions.sh b/scripts/editions.sh
new file mode 100755 (executable)
index 0000000..7913f8f
--- /dev/null
@@ -0,0 +1,61 @@
+#!/bin/bash
+
+set -euo pipefail
+
+DEFAULT_EDITION="oss"
+EDITIONS="oss"
+
+function toLower() {
+  echo "$1" | tr '[:upper:]' '[:lower:]'
+}
+
+function checkEditionArgument() {
+  local editionArg="$1"
+  local lowerEditionArg=$(toLower $editionArg)
+
+  if [ "$lowerEditionArg" == "$DEFAULT_EDITION" ]; then
+    return
+  fi
+
+  for t in $EDITIONS; do
+    if [ "$lowerEditionArg" == "$t" ]; then
+      return
+    fi
+  done
+
+  echo "Unsupported edition $editionArg"
+  exit 1
+}
+
+function distributionDirOf() {
+  local edition="$1"
+
+  if [ "$edition" = "oss" ]; then
+    echo "sonar-application/build/distributions/"
+  else
+    echo "unsupported edition $edition"
+    exit 1
+  fi
+}
+
+function baseFileNameOf() {
+  local edition="$1"
+
+  if [ "$edition" = "oss" ]; then
+    echo "sonar-application"
+  else
+    echo "unsupported edition $edition"
+    exit 1
+  fi
+}
+
+function targetDirOf() {
+  local edition="$1"
+
+  if [ "$edition" = "oss" ]; then
+    echo "sonarqube-oss"
+  else
+    echo "unsupported edition $edition"
+    exit 1
+  fi
+}
index a553c4d2ffb657fca7c922a25a73035a85b8cc30..9b84391726b7e1a8599983018ee1a4741138f3ca 100755 (executable)
@@ -1,6 +1,9 @@
 #!/bin/bash
 ###############################
-# usage: logs.sh [ -l ARG ] [ -n ARG ]
+# usage: logs.sh [ -e ARG ] [ -l ARG ] [ -n ARG ]
+#  -e ARG: edition to run
+#          valid values are 'oss' (Open Source), 'dev' (Developer), 'ent' (Enterprise) and 'ha' (HA) (case insensitive)
+#          default value is 'oss'.
 #  -l ARG: name of log file to display.
 #          valid values are 'all', 'sonar', 'web', 'ce' and 'es' (case insensitive).
 #          default value is 'all'.
 
 set -euo pipefail
 
+ROOT="$(pwd)"
+source "$ROOT/scripts/editions.sh"
+if [ -r "$ROOT/private/scripts/editions.sh" ]; then
+  source "$ROOT/private/scripts/editions.sh"
+fi
+
 DEFAULT_LOG="all"
 DEFAULT_LINES="25"
 LOGS="sonar web ce es"
@@ -37,7 +46,7 @@ function checkLogArgument() {
 }
 
 function buildTailArgs() {
-  local logArg=$(toLower $logArg)
+  local logArg="$(toLower $1)"
   local logLines="$2"
   local res=""
 
@@ -62,8 +71,11 @@ script_name=$(basename "$0")
 if [ "$script_name" == "logs.sh" ]; then
   LOG="$DEFAULT_LOG"
   LINES="$DEFAULT_LINES"
-  while getopts ":l:n:" opt; do
+  EDITION="$DEFAULT_EDITION"
+  while getopts ":e:l:n:" opt; do
     case "$opt" in
+      e) EDITION=${OPTARG:=$DEFAULT_EDITION}
+         ;;
       l) LOG=${OPTARG:=$DEFAULT_LOG}
          ;;
       n) LINES=${OPTARG:=$DEFAULT_LINES}
@@ -75,10 +87,15 @@ if [ "$script_name" == "logs.sh" ]; then
     esac
   done
 
+  checkEditionArgument "$EDITION"
   checkLogArgument "$LOG"
 
-  ROOT=$(pwd)
-  cd sonar-application/build/distributions/sonarqube-*
+  SQ_HOME_WILDCARD="$(distributionDirOf "$EDITION")/$(targetDirOf "$EDITION")/sonarqube-*"
+  if ! ls ${SQ_HOME_WILDCARD} &> /dev/null; then
+    echo "$(targetDirOf "$EDITION") is not unpacked"
+    exit 1
+  fi
+  cd ${SQ_HOME_WILDCARD}
   SQ_HOME=$(pwd)
   cd "$ROOT"
 
index b82329e15f31e5318a7f1aa34de840c2c989fba5..2a1cdfad70d5bfb8ad2e73debc365ca58d2ce4e6 100755 (executable)
@@ -1,6 +1,9 @@
 #!/bin/bash
 ###############################
-# usage: start.sh [ -p ARG ] [ -l ARG ]
+# usage: start.sh [ -e ARG ] [ -p ARG ] [ -l ARG ]
+#  -e ARG: edition to run
+#          valid values are 'oss' (Open Source), 'dev' (Developer), 'ent' (Enterprise) and 'dce' (Data Center) (case insensitive)
+#          default value is 'oss'.
 #  -p ARG: name(s) of patch separated by colon (name of patch is filename without extension)
 #  -l ARG: name of log file to display.
 #          valid values are 'all', 'sonar', 'web', 'ce' and 'es' (case insensitive).
@@ -11,13 +14,21 @@ set -euo pipefail
 
 ROOT=$(pwd)
 
-source "$ROOT"/scripts/logs.sh
+source "$ROOT/scripts/editions.sh"
+if [ -r "$ROOT/private/scripts/editions.sh" ]; then
+  source "$ROOT/private/scripts/editions.sh"
+fi
+source "$ROOT/scripts/logs.sh"
+source "$ROOT/scripts/stop.sh"
 
 PATCHES=""
+EDITION="$DEFAULT_EDITION"
 LOG="$DEFAULT_LOG"
-while getopts ":p:l:" opt; do
+while getopts ":e:p:l:" opt; do
   case "$opt" in
-    p) PATCHES=$OPTARG
+    e) EDITION=${OPTARG:=$DEFAULT_EDITION}
+       ;;
+    p) PATCHES="$OPTARG"
        ;;
     l) LOG=${OPTARG:=$DEFAULT_LOG}
        ;;
@@ -28,6 +39,7 @@ while getopts ":p:l:" opt; do
   esac
 done
 
+checkEditionArgument "$EDITION"
 checkLogArgument "$LOG"
 
 if [[ "${OSTYPE:-}" == "darwin"* ]]; then
@@ -36,26 +48,32 @@ else
   OS='linux-x86-64'
 fi
 
-if ! ls sonar-application/build/distributions/sonar-application-*.zip &> /dev/null; then
+OSS_ZIP="$(distributionDirOf "oss")/$(baseFileNameOf "oss")-*.zip"
+if ! ls ${OSS_ZIP} &> /dev/null; then
   echo 'Sources are not built'
   "$ROOT"/build.sh
 fi
 
-cd sonar-application/build/distributions/
-if ! ls sonarqube-*/bin/$OS/sonar.sh &> /dev/null; then
-  echo "Unzipping SQ..."
-  unzip -qq sonar-application-*.zip
+# stop SQ running in any instance
+stopAny
+
+cd "$(distributionDirOf "$EDITION")"
+
+TARGET_DIR="$(targetDirOf "$EDITION")"
+SH_FILE="${TARGET_DIR}/sonarqube-*/bin/$OS/sonar.sh"
+if ! ls ${SH_FILE} &> /dev/null; then
+  echo "Unpacking ${TARGET_DIR}..."
+  ZIP_FILE="$(baseFileNameOf "$EDITION")-*.zip"
+  unzip -qq ${ZIP_FILE} -d "${TARGET_DIR}"
 fi
-cd $(find sonarqube-* -type d | head -1)
+cd $(find ${TARGET_DIR}/sonarqube-* -type d | head -1)
 
 SQ_HOME=$(pwd)
 cd "$ROOT"
 
 source "$ROOT"/scripts/patches_utils.sh
 
-SQ_EXEC=$SQ_HOME/bin/$OS/sonar.sh
-
-"$SQ_EXEC" stop
+SQ_EXEC="$SQ_HOME/bin/$OS/sonar.sh"
 
 # invoke patches if at least one was specified
 # each patch is passed the path to the SQ instance home directory as first and only argument
diff --git a/scripts/stop.sh b/scripts/stop.sh
new file mode 100755 (executable)
index 0000000..f5da743
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/bash
+###############################
+# Shortcut to stop server. It must be already built.
+###############################
+
+set -euo pipefail
+
+ROOT=$(pwd)
+source "$ROOT/scripts/editions.sh"
+if [ -r "$ROOT/private/scripts/editions.sh" ]; then
+  source "$ROOT/private/scripts/editions.sh"
+fi
+
+if [[ "$OSTYPE" == "darwin"* ]]; then
+  OS='macosx-universal-64'
+else
+  OS='linux-x86-64'
+fi
+
+function stopAny() {
+  for edition in $EDITIONS; do
+      SONAR_SH="$(distributionDirOf "$edition")/$(targetDirOf "$edition")/sonarqube-*/bin/$OS/sonar.sh"
+      if ls $SONAR_SH &> /dev/null; then
+        echo "$(targetDirOf "$edition") is unpacked"
+        sh $SONAR_SH stop
+      fi
+  done
+}
+
+# check the script was called to avoid execute when script is only sourced
+script_name=$(basename "$0")
+if [ "$script_name" == "stop.sh" ]; then
+  stopAny
+fi
index 49653ff181e67c88f055ce45c3b2301a55f2cbc7..72a6ce0513616b4557453cdabc9aa2f106566a1a 100644 (file)
@@ -139,10 +139,10 @@ zip.doLast {
 }
 assemble.dependsOn zip
 
-// the script start.sh unzips distribution into $buildDir/distributions.
+// the script start.sh unpacks OSS distribution into $buildDir/distributions/sonarqube-oss.
 // This directory should be deleted when the zip is changed.
 task cleanLocalUnzippedDir(dependsOn: zip) {
-  def unzippedDir = file("$buildDir/distributions/sonarqube-$version")
+  def unzippedDir = file("$buildDir/distributions/sonarqube-oss/sonarqube-$version")
   inputs.files(file("$buildDir/distributions/sonar-application-${version}.zip"))
   outputs.upToDateWhen { true }
 
diff --git a/stop.sh b/stop.sh
deleted file mode 100755 (executable)
index e06029e1baf8636ce91e0e2ea79be0f27cea600b..0000000000000000000000000000000000000000
--- a/stop.sh
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/bin/bash
-
-# Shortcut to stop server. It must be already built.
-
-if [[ "$OSTYPE" == "darwin"* ]]; then
-  OS='macosx-universal-64'
-else
-  OS='linux-x86-64'
-fi
-
-SONAR_SH=sonar-application/build/distributions/sonarqube-*/bin/$OS/sonar.sh
-if [ -f $SONAR_SH ]; then
-  sh $SONAR_SH stop
-fi
diff --git a/stop.sh b/stop.sh
new file mode 120000 (symlink)
index 0000000000000000000000000000000000000000..b3f25aa7dc72cb0171595af34bc61b47f6c9ef2f
--- /dev/null
+++ b/stop.sh
@@ -0,0 +1 @@
+scripts/stop.sh
\ No newline at end of file