github.com/windmilleng/tilt@v0.13.6/integration/local_resource/hello.sh (about) 1 #!/bin/bash 2 3 # 1. loops printing output every couple seconds 4 # 2. writes to cleanup.txt when it gets SIGTERM 5 6 set -euo pipefail 7 8 if [[ $# == 0 ]]; then 9 echo "usage: $0 <msg>" 10 exit 1 11 fi 12 13 n=1 14 msg="$*" 15 16 cleanup() { 17 echo "cleaning up: $msg" 18 echo "cleaning up: $msg" >> cleanup.txt 19 exit 1 20 } 21 22 trap cleanup SIGTERM 23 24 while true; do 25 echo "hello! $msg #$n" 26 # run sleep in the background so the main thread is not blocked 27 # otherwise, the signal handler doesn't run until the current sleep 28 # finishes 29 sleep 2& 30 wait $! 31 n=$((n + 1)) 32 done