This is a slowly growing collection of hopefully useful and reusable shell functions and patterns. https://code.jan.io/jan/jans_shell_utils
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
931B

  1. # Copyright (c) 2022 Jan Lehnardt <jan@apache.org>, MIT licensed
  2. # inspired by https://github.com/pouchdb/pouchdb/blob/25db22fb0ff025b8d2c698da30c6c409066baa0c/bin/run-test.sh#L102-L113
  3. # Team PouchDB, Apache 2 licensed
  4. . ./lib.sh
  5. wait_for_url () {
  6. assert_arg "$1" && url="$1" || error_and_exit "url not provided, exiting"
  7. assert_arg "$2" && iterations="$2" || iterations=3
  8. assert_arg "$3" && duration="$3" || duration=1
  9. debug "called wait_for_url(url=$url, duration=$duration, iterations=$iterations)"
  10. waiting=0
  11. cmd="curl --output /dev/null --silent --insecure --head --fail --max-time 2 $url"
  12. debug_inline "waiting for $url "
  13. until ($cmd); do
  14. if [ $waiting -eq $iterations ]; then
  15. after=`expr $duration \* $iterations`
  16. debug_inline "failed, $url can not be reached after $after seconds\n"
  17. return 1
  18. fi
  19. debug_inline .
  20. waiting=`expr $waiting + 1`
  21. sleep $duration
  22. done
  23. debug_inline " succeeded\n"
  24. }