Loading src/scripts/test-db-conn +27 −22 Original line number Diff line number Diff line #!/usr/bin/env bash # -*- coding: utf-8 -*- wait_for_db() { MAX_RETRIES="$3" RETRIES_REMAINING="$MAX_RETRIES" until psql -h "$1" -d "$2" -p "$4" -c "SELECT NOW()"; do echo -e "\e[32m. . .\e[33m retrying \e[34m$1:$2\e[33m connection . . .\e[39m" sleep 5 if [ "$RETRIES_REMAINING" -lt 1 ]; then echo -e "\e[35m! ! \e[36m UNABLE TO CONNECT TO DATABASE\e[35m ! !\e[39m" echo -e "\e[32m. . \e[31mRETRY COUNT: \e[37m$MAX_RETRIES\e[39m" exit 1 fi done } DB_HOST=localhost DB_PORT=5432 DB_DB=postgres MAX_RETRIES=60 while :; do case $1 in -d|--database) DB_DB="$2" DATABASE_DB="$2" shift 2 ;; -h|--host) DB_HOST="$2" DATABASE_HOST="$2" shift 2 ;; -p|--port) DB_PORT="$2" DATABASE_PORT="$2" shift 2 ;; -r|--retries) MAX_RETRIES="$3" MAX_RETRIES="$2" shift 2 ;; -u|--user) DATABASE_USER="$2" shift 2 ;; -p|--password) DATABASE_PW="$2" shift 2 ;; *) break esac done wait_for_db "$DB_HOST" "$DB_DB" "$MAX_RETRIES" "$DB_PORT" || \ echo -e "Failed to connect to the database." RETRIES_REMAINING="$MAX_RETRIES" uri="postgresql:///$DATABASE_DB?host=$DATABASE_HOST&port=$DATABASE_PORT&password=$DATABASE_PW&user=$DATABASE_USER" echo $uri until psql $uri -c "SELECT NOW();"; do echo -e "\e[32m. . .\e[33m retrying \e[34m$1:$2\e[33m connection . . .\e[39m" sleep 5 if [ "$RETRIES_REMAINING" -lt 1 ]; then echo -e "\e[35m! ! \e[36m UNABLE TO CONNECT TO DATABASE\e[35m ! !\e[39m" echo -e "\e[32m. . \e[31mRETRY COUNT: \e[37m$MAX_RETRIES\e[39m" exit 1 fi done Loading
src/scripts/test-db-conn +27 −22 Original line number Diff line number Diff line #!/usr/bin/env bash # -*- coding: utf-8 -*- wait_for_db() { MAX_RETRIES="$3" RETRIES_REMAINING="$MAX_RETRIES" until psql -h "$1" -d "$2" -p "$4" -c "SELECT NOW()"; do echo -e "\e[32m. . .\e[33m retrying \e[34m$1:$2\e[33m connection . . .\e[39m" sleep 5 if [ "$RETRIES_REMAINING" -lt 1 ]; then echo -e "\e[35m! ! \e[36m UNABLE TO CONNECT TO DATABASE\e[35m ! !\e[39m" echo -e "\e[32m. . \e[31mRETRY COUNT: \e[37m$MAX_RETRIES\e[39m" exit 1 fi done } DB_HOST=localhost DB_PORT=5432 DB_DB=postgres MAX_RETRIES=60 while :; do case $1 in -d|--database) DB_DB="$2" DATABASE_DB="$2" shift 2 ;; -h|--host) DB_HOST="$2" DATABASE_HOST="$2" shift 2 ;; -p|--port) DB_PORT="$2" DATABASE_PORT="$2" shift 2 ;; -r|--retries) MAX_RETRIES="$3" MAX_RETRIES="$2" shift 2 ;; -u|--user) DATABASE_USER="$2" shift 2 ;; -p|--password) DATABASE_PW="$2" shift 2 ;; *) break esac done wait_for_db "$DB_HOST" "$DB_DB" "$MAX_RETRIES" "$DB_PORT" || \ echo -e "Failed to connect to the database." RETRIES_REMAINING="$MAX_RETRIES" uri="postgresql:///$DATABASE_DB?host=$DATABASE_HOST&port=$DATABASE_PORT&password=$DATABASE_PW&user=$DATABASE_USER" echo $uri until psql $uri -c "SELECT NOW();"; do echo -e "\e[32m. . .\e[33m retrying \e[34m$1:$2\e[33m connection . . .\e[39m" sleep 5 if [ "$RETRIES_REMAINING" -lt 1 ]; then echo -e "\e[35m! ! \e[36m UNABLE TO CONNECT TO DATABASE\e[35m ! !\e[39m" echo -e "\e[32m. . \e[31mRETRY COUNT: \e[37m$MAX_RETRIES\e[39m" exit 1 fi done