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.

29 lines
835 B

  1. #!/bin/sh
  2. timeout=120
  3. start="$(date +%s)"
  4. while true; do
  5. if err=$(echo "SELECT 1;" | psql 2>&1 >/dev/null); then
  6. break
  7. fi
  8. now=$(date +%s)
  9. if ! [ "$err" = "psql: FATAL: the database system is starting up" ]; then
  10. echo "postgres connection error:" \
  11. "Could not connect to '$PGHOST'. (will retry)"
  12. if [ "$err" ]; then
  13. echo " Error:" >&2
  14. printf "%s\n" "$err" | sed -r "s/^/ ! /g" >&2
  15. fi
  16. else
  17. echo "Got 'database system is starting up' error... waiting before launching npm start" >&2
  18. fi
  19. elapsed=$((now - start))
  20. if [ "$elapsed" -gt "$timeout" ]; then
  21. echo "postgre connection error:"\
  22. "Could not connect to db on '$PGHOST'" \
  23. "container's IP."
  24. exit 1
  25. fi
  26. sleep 0.5
  27. done
  28. exec npm start