Blame SOURCES/redis-shutdown

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