From 0ce4d2cae3f68626768adbae446aedcaa363af79 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Tue, 3 Jan 2017 15:41:13 +0100 Subject: [PATCH] [script] add logs.sh + tail all SQ log files in start.sh --- logs.sh | 1 + scripts/logs.sh | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ scripts/start.sh | 25 +++++++++++----- 3 files changed, 94 insertions(+), 7 deletions(-) create mode 120000 logs.sh create mode 100755 scripts/logs.sh diff --git a/logs.sh b/logs.sh new file mode 120000 index 00000000000..ac6a0b7fef1 --- /dev/null +++ b/logs.sh @@ -0,0 +1 @@ +scripts/logs.sh \ No newline at end of file diff --git a/scripts/logs.sh b/scripts/logs.sh new file mode 100755 index 00000000000..1a6f62a88a1 --- /dev/null +++ b/scripts/logs.sh @@ -0,0 +1,75 @@ +#!/bin/bash +############################### +# usage: logs.sh [ -l ARG ] [ -n ARG ] +# -l ARG: name of log file to display. +# valid values are 'all', 'sonar', 'web', 'ce' and 'es' (case insensitive). +# default value is 'all'. +# -n ARG: number of log line to display. Value is passed to n option of tail. +# default value is 25 +############################### + +set -euo pipefail + +DEFAULT_LOG="all" +DEFAULT_LINES="25" +LOGS="sonar web ce es" +function checkLogArgument() { + local logArg="$1" + if [ "${logArg,,}" == "$DEFAULT_LOG" ]; then + return + fi + for t in $LOGS; do + if [ "${logArg,,}" == "$t" ]; then + return + fi + done + echo "Unsupported -l argument $logArg" + exit 1 +} + +function buildTailArgs() { + local logArg="$1" + local logLines="$2" + local res="" + for t in $LOGS; do + if [ "${logArg,,}" == "$DEFAULT_LOG" ] || [ "${logArg,,}" == "$t" ]; then + res="$res -Fn $logLines $SQ_HOME/logs/$t.log" + fi + done + echo "$res" +} + +function doTail() { + local logArg="$1" + local logLines="${2:-"$DEFAULT_LINES"}" + TAIL_ARG=$(buildTailArgs "$logArg" "$logLines") + tail $TAIL_ARG +} + +# check the script was called to avoid execute when script is only sourced +script_name=$(basename "$0") +if [ "$script_name" == "logs.sh" ]; then + LOG="$DEFAULT_LOG" + LINES="$DEFAULT_LINES" + while getopts ":l:n:" opt; do + case "$opt" in + l) LOG=${OPTARG:=$DEFAULT_LOG} + ;; + n) LINES=${OPTARG:=$DEFAULT_LINES} + ;; + \?) + echo "Unsupported option $OPTARG" >&2 + exit 1 + ;; + esac + done + + checkLogArgument "$LOG" + + ROOT=$(pwd) + cd sonar-application/target/sonarqube-* + SQ_HOME=$(pwd) + cd "$ROOT" + + doTail "$LOG" "$LINES" +fi diff --git a/scripts/start.sh b/scripts/start.sh index a443d58441d..c4fce72fcec 100755 --- a/scripts/start.sh +++ b/scripts/start.sh @@ -1,16 +1,26 @@ #!/bin/bash ############################### -# usage: start.sh [ -p ARG ] +# usage: start.sh [ -p ARG ] [ -l ARG ] # -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). +# default value is 'all'. ############################### +set -euo pipefail + ROOT=$(pwd) +source "$ROOT"/scripts/logs.sh + PATCHES="" -while getopts ":p:" opt; do +LOG="$DEFAULT_LOG" +while getopts ":p:l:" opt; do case "$opt" in p) PATCHES=$OPTARG ;; + l) LOG=${OPTARG:=$DEFAULT_LOG} + ;; \?) echo "Unsupported option $OPTARG" >&2 exit 1 @@ -18,7 +28,9 @@ while getopts ":p:" opt; do esac done -if [[ "$OSTYPE" == "darwin"* ]]; then +checkLogArgument "$LOG" + +if [[ "${OSTYPE:-}" == "darwin"* ]]; then OS='macosx-universal-64' else OS='linux-x86-64' @@ -26,7 +38,7 @@ fi if ! ls sonar-application/target/sonarqube-*.zip &> /dev/null; then echo 'Sources are not built' - ./build.sh + "$ROOT"/build.sh fi cd sonar-application/target/ @@ -36,8 +48,6 @@ if ! ls sonarqube-*/bin/$OS/sonar.sh &> /dev/null; then fi cd sonarqube-* -# from that point on, strict bash -set -euo pipefail SQ_HOME=$(pwd) cd "$ROOT" @@ -55,4 +65,5 @@ fi "$SQ_EXEC" start sleep 1 -tail -fn 100 "$SQ_HOME"/logs/sonar.log +doTail "$LOG" + -- 2.39.5