github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/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 greeting="hello" 16 17 if [[ -f greeting ]]; then 18 greeting=$(cat greeting) 19 fi 20 21 cleanup() { 22 echo "cleaning up: $msg" 23 echo "cleaning up: $msg" >> cleanup.txt 24 exit 1 25 } 26 27 trap cleanup SIGTERM 28 29 while true; do 30 echo "$greeting! $msg #$n" 31 # run sleep in the background so the main thread is not blocked 32 # otherwise, the signal handler doesn't run until the current sleep 33 # finishes 34 sleep 2& 35 wait $! 36 n=$((n + 1)) 37 done