github.com/60ke/go-ethereum@v1.10.2/build/travis_keepalive.sh (about) 1 #!/usr/bin/env bash 2 3 # travis_keepalive runs the given command and preserves its return value, 4 # while it forks a child process what periodically produces a log line, 5 # so that Travis won't abort the build after 10 minutes. 6 7 # Why? 8 # `t.Log()` in Go holds the buffer until the test does not pass or fail, 9 # and `-race` can increase the execution time by 2-20x. 10 11 set -euo pipefail 12 13 readonly KEEPALIVE_INTERVAL=300 # seconds => 5m 14 15 main() { 16 keepalive 17 $@ 18 } 19 20 # Keepalive produces a log line in each KEEPALIVE_INTERVAL. 21 keepalive() { 22 local child_pid 23 # Note: We fork here! 24 repeat "keepalive" & 25 child_pid=$! 26 ensureChildOnEXIT "${child_pid}" 27 } 28 29 repeat() { 30 local this="$1" 31 while true; do 32 echo "${this}" 33 sleep "${KEEPALIVE_INTERVAL}" 34 done 35 } 36 37 # Ensures that the child gets killed on normal program exit. 38 ensureChildOnEXIT() { 39 # Note: SIGINT and SIGTERM are forwarded to the child process by Bash 40 # automatically, so we don't have to deal with signals. 41 42 local child_pid="$1" 43 trap "kill ${child_pid}" EXIT 44 } 45 46 main "$@"