#!/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 } tmout=120 while getFailOverStatus; do echo "I'm the primary pod and you are stopping me. Starting sentinel failover" echo "Waiting for failover to finish..." sleep 1 tmout=$((tmout - 1)) if [ "${tmout}" -le 0 ]; then echo "Failover timed out" exit 1 fi done echo "Primary has been successfuly failed over to a different pod." exit 0