Blame SOURCES/redis-shutdown

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