diff options
author | CoprDistGit <infra@openeuler.org> | 2024-11-04 03:01:09 +0000 |
---|---|---|
committer | CoprDistGit <infra@openeuler.org> | 2024-11-04 03:01:09 +0000 |
commit | 21a195c0fbaf7352a1aa708f1360e5a24034b494 (patch) | |
tree | 2682f8d2ad236cdd327bf95cf6bf9489d46fb2f8 /redis-shutdown | |
parent | 3b8dddec9264f75817af94f6e2dca3d5d753612d (diff) |
automatic import of redis6
Diffstat (limited to 'redis-shutdown')
-rw-r--r-- | redis-shutdown | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/redis-shutdown b/redis-shutdown new file mode 100644 index 0000000..1a4335a --- /dev/null +++ b/redis-shutdown @@ -0,0 +1,40 @@ +#!/bin/bash +# +# Wrapper to close properly redis and sentinel +test x"$REDIS_DEBUG" != x && set -x + +REDIS_CLI=/usr/bin/redis-cli + +# Retrieve service name +SERVICE_NAME="$1" +if [ -z "$SERVICE_NAME" ]; then + SERVICE_NAME=redis +fi + +# Get the proper config file based on service name +CONFIG_FILE="/etc/redis/$SERVICE_NAME.conf" + +# Use awk to retrieve host, port from config file +HOST=`awk '/^[[:blank:]]*bind/ { print $2 }' $CONFIG_FILE | tail -n1` +PORT=`awk '/^[[:blank:]]*port/ { print $2 }' $CONFIG_FILE | tail -n1` +PASS=`awk '/^[[:blank:]]*requirepass/ { print $2 }' $CONFIG_FILE | tail -n1` +SOCK=`awk '/^[[:blank:]]*unixsocket\s/ { print $2 }' $CONFIG_FILE | tail -n1` + +# Just in case, use default host, port +HOST=${HOST:-127.0.0.1} +if [ "$SERVICE_NAME" = redis ]; then + PORT=${PORT:-6379} +else + PORT=${PORT:-26739} +fi + +# Setup additional parameters +# e.g password-protected redis instances +[ -z "$PASS" ] || ADDITIONAL_PARAMS="-a $PASS" + +# shutdown the service properly +if [ -e "$SOCK" ] ; then + $REDIS_CLI -s $SOCK $ADDITIONAL_PARAMS shutdown +else + $REDIS_CLI -h $HOST -p $PORT $ADDITIONAL_PARAMS shutdown +fi |