Skip to content

Commit

Permalink
SONAR-10690 start.sh, stop.sh & logs.sh support SQ editions
Browse files Browse the repository at this point in the history
  • Loading branch information
sns-seb authored and SonarTech committed Jun 12, 2018
1 parent ded90fa commit 4264ca3
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 34 deletions.
61 changes: 61 additions & 0 deletions 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
}
27 changes: 22 additions & 5 deletions 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'.
Expand 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"
Expand Down Expand Up @@ -37,7 +46,7 @@ function checkLogArgument() {
}

function buildTailArgs() {
local logArg=$(toLower $logArg)
local logArg="$(toLower $1)"
local logLines="$2"
local res=""

Expand All @@ -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}
Expand All @@ -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"

Expand Down
44 changes: 31 additions & 13 deletions 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).
Expand All @@ -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}
;;
Expand All @@ -28,6 +39,7 @@ while getopts ":p:l:" opt; do
esac
done

checkEditionArgument "$EDITION"
checkLogArgument "$LOG"

if [[ "${OSTYPE:-}" == "darwin"* ]]; then
Expand All @@ -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
Expand Down
34 changes: 34 additions & 0 deletions 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
4 changes: 2 additions & 2 deletions sonar-application/build.gradle
Expand Up @@ -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 }

Expand Down
14 changes: 0 additions & 14 deletions stop.sh

This file was deleted.

1 change: 1 addition & 0 deletions stop.sh

0 comments on commit 4264ca3

Please sign in to comment.