04c73a
#!/bin/bash
04c73a
#
04c73a
# Wrapper to close properly redis and sentinel
04c73a
test x"$REDIS_DEBUG" != x && set -x
04c73a
04c73a
REDIS_CLI=/usr/bin/redis-cli
04c73a
04c73a
# Retrieve service name
04c73a
SERVICE_NAME="$1"
04c73a
if [ -z "$SERVICE_NAME" ]; then
04c73a
   SERVICE_NAME=redis
04c73a
fi
04c73a
04c73a
# Get the proper config file based on service name
04c73a
CONFIG_FILE="/etc/redis/$SERVICE_NAME.conf"
04c73a
04c73a
# Use awk to retrieve host, port from config file
04c73a
HOST=`awk '/^[[:blank:]]*bind/ { print $2 }' $CONFIG_FILE | tail -n1`
04c73a
PORT=`awk '/^[[:blank:]]*port/ { print $2 }' $CONFIG_FILE | tail -n1`
04c73a
PASS=`awk '/^[[:blank:]]*requirepass/ { print $2 }' $CONFIG_FILE | tail -n1`
04c73a
SOCK=`awk '/^[[:blank:]]*unixsocket\s/ { print $2 }' $CONFIG_FILE | tail -n1`
04c73a
04c73a
# Just in case, use default host, port
04c73a
HOST=${HOST:-127.0.0.1}
04c73a
if [ "$SERVICE_NAME" = redis ]; then
04c73a
    PORT=${PORT:-6379}
04c73a
else
04c73a
    PORT=${PORT:-26739}
04c73a
fi
04c73a
04c73a
# Setup additional parameters
04c73a
# e.g password-protected redis instances
04c73a
[ -z "$PASS"  ] || ADDITIONAL_PARAMS="-a $PASS"
04c73a
04c73a
# shutdown the service properly
04c73a
if [ -e "$SOCK" ] ; then
04c73a
	$REDIS_CLI -s $SOCK $ADDITIONAL_PARAMS shutdown
04c73a
else
04c73a
	$REDIS_CLI -h $HOST -p $PORT $ADDITIONAL_PARAMS shutdown
04c73a
fi