Blame SOURCES/redis-shutdown

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