diff --git a/falkordb-cluster/cluster-entrypoint.sh b/falkordb-cluster/cluster-entrypoint.sh index 90cc0eff..05db5d61 100755 --- a/falkordb-cluster/cluster-entrypoint.sh +++ b/falkordb-cluster/cluster-entrypoint.sh @@ -328,6 +328,26 @@ if [[ $RUN_METRICS -eq 1 ]]; then redis_exporter_pid=$! fi +reconnect_to_master(){ + res=$(redis-cli $AUTH_CONNECTION_STRING $TLS_CONNECTION_STRING info replication) + if [[ -n $res ]];then + master_info=$(redis-cli $AUTH_CONNECTION_STRING $TLS_CONNECTION_STRING info replication | grep role) + if [[ $master_info == *"role:slave"* ]];then + ip="$(echo "$res" | grep master_host | cut -d':' -f2 | tr -d '[:space:]')" + master_node_id=$(redis-cli $AUTH_CONNECTION_STRING $TLS_CONNECTION_STRING cluster nodes | grep $"ip") + echo "The master node id is: $master_node_id" + redis-cli $AUTH_CONNECTION_STRING $TLS_CONNECTION_STRING cluster replicate $master_node_id + else + echo "Node is a master, no need to resolve master hostname." + fi + else + echo "Replication did not happen yet,first time running the redis server." + fi + +} + +reconnect_to_master + while true; do sleep 1 done