feat(node): try to manage scale up and scale down

This commit is contained in:
2025-05-27 15:26:28 +02:00
parent d655d0449f
commit 004cd98224
8 changed files with 71 additions and 41 deletions

View File

@ -1,29 +1,16 @@
#!/bin/sh
vcli() {
valkey-cli -h 127.0.0.1 -p "${VALKEY_SENTINEL_PORT}" "sentinel" "$@"
return $?
}
getFailOverStatus() {
# Check if the failover is finished
local failoverStatus
primaryInfo=($(vcli get-primary-addr-by-name "mymaster"))
primaryHost=$(echo ${primaryInfo} | awk -F ' ' '{print $1}')
currentHost=$(hostname -f)
if [[ "${primaryHost}" != "${currentHost}" ]] then
echo "Failover finished"
return 0
else
echo "Failover in progress"
return 1
fi
}
source /opt/scripts/common.sh
tmout=120
while getFailOverStatus; do
while true ; do
echo "I'm the primary pod and you are stopping me. Starting sentinel failover"
echo "Waiting for failover to finish..."
fo=$(getFailOverStatus)
if [ $? -eq 0 ]; then
echo "Primary has been successfully failed over to a different pod."
break
fi
sleep 1
tmout=$((tmout - 1))
@ -32,5 +19,14 @@ while getFailOverStatus; do
exit 1
fi
done
echo "Primary has been successfuly failed over to a different pod."
echo "Removing myself from the sentinel configuration"
sentinelReset $(hostname -f)
if [ $? -ne 0 ]; then
echo "Failed to remove myself from the sentinel configuration"
exit 1
fi
exit 0