Blame SOURCES/redis-shutdown

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