feat(node): adding all in one node support

This commit is contained in:
2025-05-20 15:52:43 +02:00
parent bb6ad3532d
commit 66412ff589
15 changed files with 633 additions and 81 deletions

View File

@ -0,0 +1,27 @@
#!/bin/sh
ping_valkey() {
resp=$(timeout -s 15 $1 \
valkey-cli \
-h localhost \
-p $VALKEY_PORT \
ping)
ret=${?}
echo $resp
return ${ret}
}
response=$(ping_valkey 5)
if [ "$?" -eq "124" ]; then
echo "Timed out"
exit 1
fi
firstWord=$(echo $response | awk 'NR==1 {print $1;}')
if [ "$response" != "PONG" ] && [ "$firstWord" != "LOADING" ] && [ "$firstWord" != "MASTERDOWN" ]; then
echo "Valey is not alive [${response}]"
exit 1
fi
echo "$( date +'[%Y/%m/%d %H:%M:%S]') Valkey is alive"
exit 0

View File

@ -0,0 +1,28 @@
#!/bin/sh
ping_sentinel() {
resp=$(timeout -s 15 $1 \
valkey-cli \
-h localhost \
-p $VALKEY_SENTINEL_PORT \
ping)
ret=${?}
echo $resp
return ${ret}
}
response=$(ping_sentinel 5)
if [ "${?}" -eq 124 ]; then
echo "Sentinel ping timed out"
exit 124
fi
if [ "${response}" != "PONG" ];
then
echo "Sentinel is not responding"
exit 1
fi
echo "$( date +'[%Y/%m/%d %H:%M:%S]') Sentinel is responding"
exit 0

View File

@ -0,0 +1,50 @@
#!/bin/bash
# Run Valkey command
vcli() {
valkey_cli -h 127.0.0.1 -P "${VALKEY_PORT}" "$@"
return $?
}
# Run Sentinel command
vscli() {
valkey-cli -h "$VALKEY_SERVICE" -p "$VALKEY_SENTINEL_PORT" sentinel "$@"
return $?
}
sentinelFailOverFinished() {
# Check if the failover is finished
local failoverStatus
primaryInfo=$(vscli get-primary-by-name "mymaster")
primaryHost=${primaryInfo[0]}
fullPrimaryHostname="${primaryHost}.${HEADLESS_SERVICE}"
[[ "${fullPrimaryHostname}" == "${HOSTNAME}}" ]]
}
if [ "${VALKEY_ROLE}" = "replication"]; then
echo "Stopping replication"
ROLE=$(vcli role | head 1)
if [ "${ROLE}" = "master" ]; then
#Pausing write connections to avoid data loss"
vcli CLIENT PAUSE "22000"
echo "Failover in progress"
vscli failover "mymaster"
i=0
while true; do
sentinelFailOverFinished
if [ $? -eq 0 ]; then
echo "Failover finished"
break
fi
sleep 1
i=$((i + 1))
if [ $i -gt 60 ]; then
echo "Failover timed out"
exit 1
fi
done
else
exit 0
fi
fi

View File

@ -0,0 +1,26 @@
#!/bin/sh
ping_valkey() {
resp=$(timeout -s 15 $1 \
valkey-cli \
-h localhost \
-p $VALKEY_PORT \
ping)
ret=${?}
echo $resp
return ${ret}
}
response=$(ping_valkey 5)
if [ "$?" -eq "124" ]; then
echo "Timed out"
exit 1
fi
if [ "$response" != "PONG" ]; then
echo "Valey is not ready [${response}]"
exit 1
fi
echo "$( date +'[%Y/%m/%d %H:%M:%S]') Valkey is ready"
exit 0