Blame SOURCES/redis-shutdown

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