aboutsummaryrefslogtreecommitdiff
path: root/scripts/retry-on-SIGSEGV.sh
blob: c8f71f76d32379b131c38ce3fbd94252b36abb1f (plain)
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
#!/usr/bin/env bash

retries=$1
shift

echo "Will retry '$*' for ${retries} times:"

function needsRetry() {
  if [[ -d "build-logging" ]]; then
    local contents
    contents=$(cat "$(ls -t build-logging/*.log | head -1)")

    [[ "$contents" =~ .*"finished with non-zero exit value 134".* ]] && echo "RETRY"
  else
    echo "RETRY-NO-LOGGING-FOLDER"
  fi
}

set +e
count=0
"$@"
EXIT_CODE=$?
while needsRetry; do
  count=$((count + 1))
  if [[ ${count} -lt ${retries} ]]; then
    echo "************** Retry ${count}/${retries} exited ${EXIT_CODE}, retrying in ${count} seconds..."
    ./gradlew --stop
    sleep ${count}
    "$@"
    EXIT_CODE=$?
    echo "EXIT_CODE is ${EXIT_CODE}"
  else
    echo "Retry ${count}/${retries} exited ${EXIT_CODE}, no more retries left."
    exit ${EXIT_CODE}
  fi
done