-
Notifications
You must be signed in to change notification settings - Fork 134
/
check-restart-logs.sh
executable file
·61 lines (53 loc) · 1.74 KB
/
check-restart-logs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env bash
# Checks if log files from pod restarts have patterns that indicate the restart is ok.
# It returns a zero exit status if all log files have an ok indicating pattern.
set -e
DIR="$(cd "$(dirname "$0")" && pwd)"
if [[ -z "$*" || $# -lt 2 ]]; then
echo "Usage: check-restart-logs.sh <CI job> <files...>"
exit 1
fi
job=$1
shift
for logfile in "$@"; do
if [[ ! -f "${logfile}" ]]; then
echo "Error: the log file '${logfile}' does not exist"
exit 1
fi
done
patterns=$(jq -c '.[]' "$DIR/restart-ok-patterns.json")
(
IFS='
'
all_ok=true
for logfile in "$@"; do
echo "Checking for a restart exception in: ${logfile}"
this_log_is_ok=false
for pattern in $patterns; do
comment=$(echo "$pattern" | jq -r '.comment')
job_pattern=$(echo "$pattern" | jq -r '.job')
logfile_pattern=$(echo "$pattern" | jq -r '.logfile')
logline_pattern=$(echo "$pattern" | jq -r '.logline')
if [[ "${job}" =~ ${job_pattern} ]] &&
[[ "${logfile}" =~ ${logfile_pattern} ]] &&
egrep -q "${logline_pattern}" "${logfile}"
then
echo "Ignoring this restart due to: ${comment}"
this_log_is_ok=true
break
fi
done
if ! ${this_log_is_ok}; then
echo "This restart does not match any ignore patterns"
if [[ -n "${ARTIFACT_DIR:-}" ]]; then
cp "${logfile}" "${ARTIFACT_DIR}" || true
echo "$(basename "${logfile}") copied to Artifacts" # do not change - required by pod restart check
fi
all_ok=false
fi
done
if ! ${all_ok}; then
exit 2
fi
)
exit 0