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