added master/slave replication support

This commit is contained in:
Sameer Naik
2015-11-16 14:29:32 +05:30
parent d1de517649
commit 015cab4874
2 changed files with 47 additions and 0 deletions

View File

@@ -7,6 +7,51 @@ set_redis_password() {
fi
}
configure_replication() {
if [ "$REDIS_REPLICATION_MODE" == "slave" ]; then
echo ""
echo "==> Setting up Redis slave..."
echo "==> Trying to fetch Redis replication parameters from the master link..."
REDIS_MASTER_HOST=${REDIS_MASTER_HOST:-$MASTER_PORT_6379_TCP_ADDR}
REDIS_MASTER_PORT=${REDIS_MASTER_PORT:-$MASTER_PORT_6379_TCP_PORT}
REDIS_MASTER_PASSWORD=${REDIS_MASTER_PASSWORD:-$MASTER_ENV_REDIS_PASSWORD}
if [ ! $REDIS_MASTER_HOST ]; then
echo "In order to setup a replication slave you need to provide the REDIS_MASTER_HOST as well"
echo ""
exit -1
fi
if [ ! $REDIS_MASTER_PORT ]; then
echo "REDIS_MASTER_PORT not specified. Defaulting to 6379"
echo ""
POSTGRESQL_MASTER_PORT=${POSTGRESQL_MASTER_PORT:-6379}
fi
echo "==> Checking if master is ready to accept connection (60s timeout)..."
timeout=60
while ! redis-cli -h $REDIS_MASTER_HOST -p $REDIS_MASTER_PORT ${REDIS_MASTER_PASSWORD:+-a $REDIS_MASTER_PASSWORD} ping >/dev/null 2>&1
do
timeout=$(expr $timeout - 1)
if [[ $timeout -eq 0 ]]; then
echo ""
echo "Could not connect to replication master"
echo ""
exit -1
fi
sleep 1
done
echo "==> Setting the master configuration..."
sed 's|^[#]*[ ]*slaveof .*|slaveof '"$REDIS_MASTER_HOST"' '"$REDIS_MASTER_PORT"'|' -i $BITNAMI_APP_DIR/etc/conf/redis.conf
if [ $REDIS_MASTER_PASSWORD ]; then
sed 's|^[#]*[ ]*masterauth .*|masterauth '"$REDIS_MASTER_PASSWORD"'|' -i $BITNAMI_APP_DIR/etc/conf/redis.conf
fi
echo ""
fi
}
print_redis_password() {
if [ -z $REDIS_PASSWORD ]; then
echo "**none**"

View File

@@ -12,6 +12,8 @@ else
print_container_already_initialized $BITNAMI_APP_NAME
fi
configure_replication
chown -R $BITNAMI_APP_USER:$BITNAMI_APP_USER $BITNAMI_APP_VOL_PREFIX/data/ \
$BITNAMI_APP_VOL_PREFIX/logs/ \
$BITNAMI_APP_VOL_PREFIX/conf/ || true