redis 服务启停管理脚本 留存备用

360影视 2025-01-09 04:02 2

摘要:#!/bin/bashCURRENT_DIR=$(cd "$(dirname "$0")"; pwd)cd $CURRENT_DIRumask 077source ~/.bash_profilesource ./common.shstart {if [[ -f

#!/bin/bash

CURRENT_DIR=$(cd "$(dirname "$0")"; pwd)

cd $CURRENT_DIR

umask 077

source ~/.bash_profile

source ./common.sh

start {

if [[ -f $INSTALL_DIR/redis/redis/config/redis_6379.conf ]];then

echo "starting cluster..."

$INSTALL_DIR/redis/redis/bin/redis-server $INSTALL_DIR/redis/redis/config/redis_6379.conf

$INSTALL_DIR/redis/redis/bin/redis-server $INSTALL_DIR/redis/redis/config/redis_6389.conf

else

echo "starting sentinel..."

$INSTALL_DIR/redis/redis/bin/redis-server $INSTALL_DIR/redis/redis/config/redis.conf

$INSTALL_DIR/redis/redis/bin/redis-sentinel $INSTALL_DIR/redis/redis/config/sentinel.conf

fi

}

stop {

if [[ -n "$(ps aux | grep redis/bin/redis | grep -v grep)" ]]; then

pkill -f redis/bin/redis

if [[ $(ps aux | grep redis/bin/redis | grep -v grep | wc -l) -ne 0 ]]; then

sleep 5

fi

else

echo "redis is not running!"

fi

}

status {

if [[ -f $INSTALL_DIR/redis/redis/config/redis_6379.conf ]];then

check_service --service-name redis --shell="

else

pid=`ps -ef | grep "$INSTALL_DIR/redis/redis/bin" | grep -v 'grep' | awk '{print $2}' | sed 's/^ //g;s/ $//g'`

if [[ ! -z "$pid" ]]; then

check_service --service-name redis --shell="

else

echo "redis not running!"

exit 3

fi

fi

}

case $1 in

start)

start

;;

stop)

stop

;;

restart)

stop

sleep 5

start

;;

status)

status

;;

esac

来源:小贺看科技

相关推荐