feat(node): adding all in one node support
This commit is contained in:
27
resources/node/files/scripts/liveness-local.sh
Normal file
27
resources/node/files/scripts/liveness-local.sh
Normal 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
|
28
resources/node/files/scripts/ping-sentinel.sh
Normal file
28
resources/node/files/scripts/ping-sentinel.sh
Normal 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
|
0
resources/node/files/scripts/pre-start-sentinel.sh
Normal file
0
resources/node/files/scripts/pre-start-sentinel.sh
Normal file
50
resources/node/files/scripts/pre-stop.sh
Normal file
50
resources/node/files/scripts/pre-stop.sh
Normal 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
|
26
resources/node/files/scripts/readiness-local.sh
Normal file
26
resources/node/files/scripts/readiness-local.sh
Normal 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
|
Reference in New Issue
Block a user