feat(node): try to manage scale up and scale down
This commit is contained in:
@ -14,6 +14,31 @@ pingSentinel() {
|
||||
return ${ret}
|
||||
}
|
||||
|
||||
getPrimaryInfo() {
|
||||
valkey-cli --csv -h ${VALKEY_SERVICE} -p ${VALKEY_SENTINEL_PORT} sentinel get-primary-addr-by-name "mymaster"| \
|
||||
awk -F ',' '{ gsub(/"/,"",$0); print $1 " " $2 }'
|
||||
return ${?}
|
||||
}
|
||||
|
||||
getSentinelMasterName() {
|
||||
getPrimaryInfo | awk -F ' ' '{print $1}'
|
||||
}
|
||||
|
||||
getFailOverStatus() {
|
||||
# Check if the failover is finished
|
||||
local failoverStatus
|
||||
primaryInfo=$(getPrimaryInfo)
|
||||
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
|
||||
}
|
||||
|
||||
waitForSentinel() {
|
||||
tout=60
|
||||
while true; do
|
||||
@ -35,16 +60,6 @@ waitForSentinel() {
|
||||
sleep 10
|
||||
}
|
||||
|
||||
getPrimaryInfo() {
|
||||
valkey-cli --csv -h ${VALKEY_SERVICE} -p ${VALKEY_SENTINEL_PORT} sentinel get-primary-addr-by-name "mymaster"| \
|
||||
awk -F ',' '{ gsub(/"/,"",$0); print $1 " " $2 }'
|
||||
return ${?}
|
||||
}
|
||||
|
||||
getSentinelMasterName() {
|
||||
getPrimaryInfo | awk -F ' ' '{print $1}'
|
||||
}
|
||||
|
||||
sentinelIsMaster() {
|
||||
# Check if the sentinel is master
|
||||
primaryInfo=$(getPrimaryInfo)
|
||||
@ -57,4 +72,10 @@ sentinelIsMaster() {
|
||||
echo "Sentinel is master"
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
sentinelReset() {
|
||||
# Reset the sentinel
|
||||
valkey-cli -h ${VALKEY_SERVICE} -p ${VALKEY_SENTINEL_PORT} sentinel reset "${1}"
|
||||
return $?
|
||||
}
|
Reference in New Issue
Block a user