diff --git a/gerer_bot.sh b/gerer_bot.sh new file mode 100644 index 0000000..98cb4d1 --- /dev/null +++ b/gerer_bot.sh @@ -0,0 +1,11 @@ +#!/bin/bash +ROLE=$(./verifier_role_db.sh) +BOT_TOURNE=$(docker ps -q -f name=bot-discord) + +if [ "$ROLE" = "primary" ] && [ -z "$BOT_TOURNE" ]; then + docker start bot-discord +fi + +if [ "$ROLE" = "replica" ] && [ -n "$BOT_TOURNE" ]; then + docker stop bot-discord +fi diff --git a/verifier_role_db.sh b/verifier_role_db.sh new file mode 100644 index 0000000..dc17a4d --- /dev/null +++ b/verifier_role_db.sh @@ -0,0 +1,3 @@ +#!/bin/bash +ROLE=$(psql -U postgres -tAc "SELECT pg_is_in_recovery();") +[ "$ROLE" = "f" ] && echo "primary" || echo "replica"