2023-05-24 21:56:22 +08:00
|
|
|
#!/bin/bash
|
2024-04-20 02:11:38 +08:00
|
|
|
if [ "$EUID" -ne 0 ]; then
|
|
|
|
echo "Please run this script as root ( or with sudo )" ;
|
|
|
|
exit 1;
|
|
|
|
fi;
|
|
|
|
|
|
|
|
cd "$(dirname "$0")"
|
2023-05-24 21:56:22 +08:00
|
|
|
|
|
|
|
export LANGUAGE="en_US.UTF-8"
|
|
|
|
export LC_ALL="en_US.UTF-8"
|
|
|
|
|
|
|
|
akka_apps_status=$(systemctl is-active "bbb-apps-akka")
|
|
|
|
hasura_status=$(systemctl is-active "bbb-graphql-server")
|
|
|
|
|
|
|
|
if [ "$akka_apps_status" = "active" ]; then
|
|
|
|
echo "Stopping Akka-apps"
|
|
|
|
sudo systemctl stop bbb-apps-akka
|
|
|
|
fi
|
|
|
|
if [ "$hasura_status" = "active" ]; then
|
|
|
|
echo "Stopping Hasura"
|
2023-08-08 21:41:16 +08:00
|
|
|
sudo systemctl stop bbb-graphql-server
|
2023-05-24 21:56:22 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Restarting database bbb_graphql"
|
2024-02-21 02:38:33 +08:00
|
|
|
runuser -u postgres -- psql -q -c "drop database if exists bbb_graphql with (force)"
|
|
|
|
runuser -u postgres -- psql -q -c "create database bbb_graphql WITH TEMPLATE template0 LC_COLLATE 'C.UTF-8'"
|
|
|
|
runuser -u postgres -- psql -q -c "alter database bbb_graphql set timezone to 'UTC'"
|
2023-05-24 21:56:22 +08:00
|
|
|
|
|
|
|
echo "Creating tables in bbb_graphql"
|
2023-11-28 22:36:07 +08:00
|
|
|
runuser -u postgres -- psql -U postgres -d bbb_graphql -q -f bbb_schema.sql --set ON_ERROR_STOP=on
|
2023-05-24 21:56:22 +08:00
|
|
|
|
2024-01-30 23:35:39 +08:00
|
|
|
echo "Creating frontend in bbb_graphql"
|
|
|
|
DATABASE_FRONTEND_USER="bbb_frontend"
|
|
|
|
FRONT_USER_EXISTS=$(sudo -u postgres psql -U postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname = '$DATABASE_FRONTEND_USER'")
|
|
|
|
if [ "$FRONT_USER_EXISTS" = '1' ]
|
|
|
|
then
|
|
|
|
echo "User $DATABASE_FRONTEND_USER already exists"
|
|
|
|
else
|
|
|
|
sudo -u postgres psql -q -c "CREATE USER $DATABASE_FRONTEND_USER WITH PASSWORD '$DATABASE_FRONTEND_USER'"
|
|
|
|
sudo -u postgres psql -q -c "GRANT CONNECT ON DATABASE bbb_graphql TO $DATABASE_FRONTEND_USER"
|
|
|
|
sudo -u postgres psql -q -d bbb_graphql -c "REVOKE ALL ON ALL TABLES IN SCHEMA public FROM $DATABASE_FRONTEND_USER"
|
|
|
|
sudo -u postgres psql -q -d bbb_graphql -c "GRANT USAGE ON SCHEMA public TO $DATABASE_FRONTEND_USER"
|
|
|
|
echo "User $DATABASE_FRONTEND_USER created on database bbb_graphql"
|
2023-05-24 21:56:22 +08:00
|
|
|
fi
|
2024-01-30 23:35:39 +08:00
|
|
|
|
2024-02-02 21:52:50 +08:00
|
|
|
sudo -u postgres psql -q -d bbb_graphql -c "GRANT SELECT ON v_user_connection_auth TO $DATABASE_FRONTEND_USER"
|
2024-01-30 23:35:39 +08:00
|
|
|
|
2024-02-21 02:30:22 +08:00
|
|
|
echo "Starting Hasura"
|
|
|
|
sudo systemctl start bbb-graphql-server
|
|
|
|
|
|
|
|
#Check if Hasura is ready before applying metadata
|
2024-05-07 22:39:34 +08:00
|
|
|
HASURA_PORT=8085
|
2024-02-21 02:30:22 +08:00
|
|
|
while ! netstat -tuln | grep ":$HASURA_PORT " > /dev/null; do
|
|
|
|
echo "Waiting for Hasura's port ($HASURA_PORT) to be ready..."
|
|
|
|
sleep 1
|
|
|
|
done
|
|
|
|
|
2023-05-24 21:56:22 +08:00
|
|
|
if [ "$akka_apps_status" = "active" ]; then
|
|
|
|
echo "Starting Akka-apps"
|
|
|
|
sudo systemctl start bbb-apps-akka
|
|
|
|
fi
|
2023-08-08 21:41:16 +08:00
|
|
|
|
|
|
|
echo "Applying new metadata to Hasura"
|
2024-02-21 02:30:22 +08:00
|
|
|
timeout 15s hasura metadata apply --skip-update-check
|