2020-10-23 17:59:08 +03:00
|
|
|
#!/bin/bash -e -o pipefail
|
2023-11-28 02:25:03 +01:00
|
|
|
################################################################################
|
|
|
|
|
## File: install-postgresql.sh
|
|
|
|
|
## Desc: Install PostgreSQL
|
|
|
|
|
################################################################################
|
|
|
|
|
|
2020-12-28 10:54:25 +03:00
|
|
|
source ~/utils/utils.sh
|
2020-09-10 14:34:08 +03:00
|
|
|
|
2021-11-16 11:43:59 +03:00
|
|
|
# Fetch PostgreSQL version to install from the toolset
|
|
|
|
|
toolsetVersion=$(get_toolset_value '.postgresql.version')
|
2020-09-10 14:34:08 +03:00
|
|
|
|
2021-11-16 11:43:59 +03:00
|
|
|
# Install latest version of PostgreSQL
|
|
|
|
|
brew_smart_install postgresql@$toolsetVersion
|
|
|
|
|
|
|
|
|
|
# Service PostgreSQL should be started before use
|
2022-08-30 20:06:24 +03:00
|
|
|
postgreService=$(brew services list | grep -oe "postgresql\S*")
|
|
|
|
|
brew services start $postgreService
|
2020-09-10 14:34:08 +03:00
|
|
|
|
2021-11-16 11:43:59 +03:00
|
|
|
# Verify PostgreSQL is ready for accept incoming connections
|
2020-10-23 17:59:08 +03:00
|
|
|
echo "Check PostgreSQL service is running"
|
|
|
|
|
i=10
|
|
|
|
|
COMMAND='pg_isready'
|
2024-01-09 14:47:31 +01:00
|
|
|
while [[ $i -gt 0 ]]; do
|
2020-10-23 17:59:08 +03:00
|
|
|
echo "Check PostgreSQL service status"
|
|
|
|
|
eval $COMMAND && break
|
|
|
|
|
((i--))
|
2024-01-09 14:47:31 +01:00
|
|
|
if [[ $i == 0 ]]; then
|
2020-10-23 17:59:08 +03:00
|
|
|
echo "PostgreSQL service not ready, all attempts exhausted"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
echo "PostgreSQL service not ready, wait 10 more sec, attempts left: $i"
|
|
|
|
|
sleep 10
|
|
|
|
|
done
|
2020-09-10 14:34:08 +03:00
|
|
|
|
2021-11-16 11:43:59 +03:00
|
|
|
# Stop PostgreSQL
|
2022-08-30 20:06:24 +03:00
|
|
|
brew services stop $postgreService
|
2021-01-14 00:46:44 +07:00
|
|
|
|
2021-01-22 09:26:28 +03:00
|
|
|
invoke_tests "Databases" "PostgreSQL"
|