Skip to content

Commit

Permalink
adapt when cluster ip
Browse files Browse the repository at this point in the history
  • Loading branch information
drivebyer committed Dec 5, 2023
1 parent f5f9513 commit fb04bc1
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions arm64/images/ot-redis/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -66,26 +69,27 @@ 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
# append:
# 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() {
Expand Down

0 comments on commit fb04bc1

Please sign in to comment.