#!/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 | |||||
} |
#!/bin/bash | #!/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. | # -l ARG: name of log file to display. | ||||
# valid values are 'all', 'sonar', 'web', 'ce' and 'es' (case insensitive). | # valid values are 'all', 'sonar', 'web', 'ce' and 'es' (case insensitive). | ||||
# default value is 'all'. | # default value is 'all'. | ||||
set -euo pipefail | 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_LOG="all" | ||||
DEFAULT_LINES="25" | DEFAULT_LINES="25" | ||||
LOGS="sonar web ce es" | LOGS="sonar web ce es" | ||||
} | } | ||||
function buildTailArgs() { | function buildTailArgs() { | ||||
local logArg=$(toLower $logArg) | |||||
local logArg="$(toLower $1)" | |||||
local logLines="$2" | local logLines="$2" | ||||
local res="" | local res="" | ||||
if [ "$script_name" == "logs.sh" ]; then | if [ "$script_name" == "logs.sh" ]; then | ||||
LOG="$DEFAULT_LOG" | LOG="$DEFAULT_LOG" | ||||
LINES="$DEFAULT_LINES" | LINES="$DEFAULT_LINES" | ||||
while getopts ":l:n:" opt; do | |||||
EDITION="$DEFAULT_EDITION" | |||||
while getopts ":e:l:n:" opt; do | |||||
case "$opt" in | case "$opt" in | ||||
e) EDITION=${OPTARG:=$DEFAULT_EDITION} | |||||
;; | |||||
l) LOG=${OPTARG:=$DEFAULT_LOG} | l) LOG=${OPTARG:=$DEFAULT_LOG} | ||||
;; | ;; | ||||
n) LINES=${OPTARG:=$DEFAULT_LINES} | n) LINES=${OPTARG:=$DEFAULT_LINES} | ||||
esac | esac | ||||
done | done | ||||
checkEditionArgument "$EDITION" | |||||
checkLogArgument "$LOG" | 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) | SQ_HOME=$(pwd) | ||||
cd "$ROOT" | cd "$ROOT" | ||||
#!/bin/bash | #!/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) | # -p ARG: name(s) of patch separated by colon (name of patch is filename without extension) | ||||
# -l ARG: name of log file to display. | # -l ARG: name of log file to display. | ||||
# valid values are 'all', 'sonar', 'web', 'ce' and 'es' (case insensitive). | # valid values are 'all', 'sonar', 'web', 'ce' and 'es' (case insensitive). | ||||
ROOT=$(pwd) | 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="" | PATCHES="" | ||||
EDITION="$DEFAULT_EDITION" | |||||
LOG="$DEFAULT_LOG" | LOG="$DEFAULT_LOG" | ||||
while getopts ":p:l:" opt; do | |||||
while getopts ":e:p:l:" opt; do | |||||
case "$opt" in | case "$opt" in | ||||
p) PATCHES=$OPTARG | |||||
e) EDITION=${OPTARG:=$DEFAULT_EDITION} | |||||
;; | |||||
p) PATCHES="$OPTARG" | |||||
;; | ;; | ||||
l) LOG=${OPTARG:=$DEFAULT_LOG} | l) LOG=${OPTARG:=$DEFAULT_LOG} | ||||
;; | ;; | ||||
esac | esac | ||||
done | done | ||||
checkEditionArgument "$EDITION" | |||||
checkLogArgument "$LOG" | checkLogArgument "$LOG" | ||||
if [[ "${OSTYPE:-}" == "darwin"* ]]; then | if [[ "${OSTYPE:-}" == "darwin"* ]]; then | ||||
OS='linux-x86-64' | OS='linux-x86-64' | ||||
fi | 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' | echo 'Sources are not built' | ||||
"$ROOT"/build.sh | "$ROOT"/build.sh | ||||
fi | 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 | fi | ||||
cd $(find sonarqube-* -type d | head -1) | |||||
cd $(find ${TARGET_DIR}/sonarqube-* -type d | head -1) | |||||
SQ_HOME=$(pwd) | SQ_HOME=$(pwd) | ||||
cd "$ROOT" | cd "$ROOT" | ||||
source "$ROOT"/scripts/patches_utils.sh | 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 | # 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 | # each patch is passed the path to the SQ instance home directory as first and only argument |
#!/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 |
} | } | ||||
assemble.dependsOn zip | 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. | // This directory should be deleted when the zip is changed. | ||||
task cleanLocalUnzippedDir(dependsOn: zip) { | 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")) | inputs.files(file("$buildDir/distributions/sonar-application-${version}.zip")) | ||||
outputs.upToDateWhen { true } | outputs.upToDateWhen { true } | ||||
#!/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 |
scripts/stop.sh |