Files
gangyan/scripts/redis-restart.sh

19 lines
800 B
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# 须用 bash 执行;若误用 sh/dash 会自动改用 bash 再跑一遍
[ -n "${BASH_VERSION:-}" ] || exec /usr/bin/env bash "$0" ${1+"$@"}
# 重启 Redis 容器 redis-server若不存在则创建与 start_all.sh 一致)
# 日志gangyan/logs/redis.log
set -u
source "$(cd "$(dirname "$0")" && pwd)/common-restart.sh"
LOG_FILE="$LOG_DIR/redis.log"
log_tee "======== 重启 Redis ========"
if docker ps -a --format '{{.Names}}' | grep -qx 'redis-server'; then
docker restart redis-server 2>&1 | tee -a "$LOG_FILE"
else
log_tee "容器不存在,尝试创建..."
docker run -d --name redis-server -p 6379:6379 redis:7-alpine 2>&1 | tee -a "$LOG_FILE"
fi
log_tee "完成。docker ps redis-server ->"
docker ps --filter name=redis-server 2>&1 | tee -a "$LOG_FILE"