aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/editions.sh61
-rwxr-xr-xscripts/logs.sh27
-rwxr-xr-xscripts/start.sh44
-rwxr-xr-xscripts/stop.sh34
4 files changed, 148 insertions, 18 deletions
diff --git a/scripts/editions.sh b/scripts/editions.sh
new file mode 100755
index 00000000000..7913f8fec9a
--- /dev/null
+++ b/scripts/editions.sh
@@ -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
+}
diff --git a/scripts/logs.sh b/scripts/logs.sh
index a553c4d2ffb..9b84391726b 100755
--- a/scripts/logs.sh
+++ b/scripts/logs.sh
@@ -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'.
@@ -10,6 +13,12 @@
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"
diff --git a/scripts/start.sh b/scripts/start.sh
index b82329e15f3..2a1cdfad70d 100755
--- a/scripts/start.sh
+++ b/scripts/start.sh
@@ -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
index 00000000000..f5da7431230
--- /dev/null
+++ b/scripts/stop.sh
@@ -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