Blame SOURCES/redis-shutdown

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