From fb04bc137ce93b935e148b9564f87f99e869f8c1 Mon Sep 17 00:00:00 2001 From: drivebyer Date: Tue, 5 Dec 2023 15:03:24 +0800 Subject: [PATCH] adapt when cluster ip --- arm64/images/ot-redis/entrypoint.sh | 34 ++++++++++++++++------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/arm64/images/ot-redis/entrypoint.sh b/arm64/images/ot-redis/entrypoint.sh index f833d08ec..0a74b8972 100644 --- a/arm64/images/ot-redis/entrypoint.sh +++ b/arm64/images/ot-redis/entrypoint.sh @@ -43,8 +43,11 @@ redis_mode_setup() { if [[ -z "${POD_IP}" ]]; then POD_IP=$(hostname -i) fi - - #sed -i -e "/myself/ s/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/${POD_IP}/" "${DATA_DIR}/nodes.conf" + local nodePortConf=$(grep "$(hostname)" "${EXTERNAL_CONFIG_FILE}") + if [[ -z "${nodePortConf}" ]]; then + echo "No nodeport config found for ${hostname}" + sed -i -e "/myself/ s/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/${POD_IP}/" "${DATA_DIR}/nodes.conf" + fi else echo "Setting up redis in standalone mode" fi @@ -66,7 +69,7 @@ persistence_setup() { } external_config() { - # content in /etc/redis/external.conf.d/redis-external.conf like: + # nodeport config content in /etc/redis/external.conf.d/redis-external.conf like: # $(hostname) ip port bus-port # we need to find the line which contains the hostname of current pod # and append it to /etc/redis/redis.conf @@ -74,18 +77,19 @@ external_config() { # 1. cluster-announce-ip # 2. cluster-announce-port # 3. cluster-announce-bus-port - - local hostname=$(hostname) - local line=$(grep "${hostname}" "${EXTERNAL_CONFIG_FILE}") - local ip=$(echo "${line}" | awk '{print $2}') - local port=$(echo "${line}" | awk '{print $3}') - local bus_port=$(echo "${line}" | awk '{print $4}') - - echo "cluster-announce-ip ${ip}" >> /etc/redis/redis.conf - echo "cluster-announce-port ${port}" >> /etc/redis/redis.conf - echo "cluster-announce-bus-port ${bus_port}" >> /etc/redis/redis.conf - - #echo "include ${EXTERNAL_CONFIG_FILE}" >> /etc/redis/redis.conf + local nodePortConf=$(grep "$(hostname)" "${EXTERNAL_CONFIG_FILE}") + if [[ -z "${nodePortConf}" ]]; then + echo "No nodeport config found for ${hostname}" + echo "include ${EXTERNAL_CONFIG_FILE}" >> /etc/redis/redis.conf + else + echo "Found nodeport config for ${hostname}" + local ip=$(echo "${line}" | awk '{print $2}') + local port=$(echo "${line}" | awk '{print $3}') + local bus_port=$(echo "${line}" | awk '{print $4}') + echo "cluster-announce-ip ${ip}" >> /etc/redis/redis.conf + echo "cluster-announce-port ${port}" >> /etc/redis/redis.conf + echo "cluster-announce-bus-port ${bus_port}" >> /etc/redis/redis.conf + fi } start_redis() {