CentOS 7.6 系统中监控redis停止后自动启动的脚本

在 CentOS 7.6 系统中监控 Redis 停止后自动启动的 bash 脚本的例子:

#!/bin/bash

while true
do
# Check if Redis is running
redis_status=$(systemctl status redis | grep "active (running)")
if [ -z "$redis_status" ]; then
# If Redis is not running, start it
systemctl start redis
fi
# Sleep for 30 seconds
sleep 30
done

此脚本检查 Redis 的状态,如果它没有运行,则启动它。此脚本将每隔 30 秒检查一次 Redis 的状态。

可以根据自己的需求对其进行修改。您可以使用 cron 服务定期运行此脚本,以确保 Redis 总是运行。