aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/logs.sh
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-01-03 15:41:13 +0100
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-01-03 15:41:42 +0100
commit0ce4d2cae3f68626768adbae446aedcaa363af79 (patch)
tree7e9f25cb811c3978bf4612afcbba6f322d52135c /scripts/logs.sh
parentdb1328e1e12a94c565d94a43db203e3d11af3321 (diff)
downloadsonarqube-0ce4d2cae3f68626768adbae446aedcaa363af79.tar.gz
sonarqube-0ce4d2cae3f68626768adbae446aedcaa363af79.zip
[script] add logs.sh + tail all SQ log files in start.sh
Diffstat (limited to 'scripts/logs.sh')
-rwxr-xr-xscripts/logs.sh75
1 files changed, 75 insertions, 0 deletions
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