Blame SOURCES/redis-shutdown

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