redis server和sentinel在Linux系统下的自启动脚本

 官方给的启动脚本是发布包里的utils/redis_init_script文件。下面的脚本只是在官方脚本的基础上加了一点注释,和chkconfig。而sentinel实际上也是redis-server,只是另一种启动模式而已,所以它的启动脚本基本和redis-server的基本一致,只改一下可执行文件和配置文件即可。

redis-server:

#!/bin/sh
#
# chkconfig: 2345 55 25
# description: Redis server daemon
#
# processname: redis_6379 #需要修改与$port相同
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=6387   # 需要修改与$port相同
BINPATH=/usr/local/redis/bin
EXEC=${BINPATH}/redis-server
CLIEXEC=${BINPATH}/redis-cli
PIDFILE=/data/redis/run/redis_${REDISPORT}.pid # pid file created by redis server as configured in the configuation file below.
CONF="/data/redis/conf/redis-conf/redis_${REDISPORT}.conf"
case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
                echo "$PIDFILE exists, process is already running or crashed"
        else
                echo "Starting Redis $REDISPORT ..."
                $EXEC $CONF
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $CLIEXEC -p $REDISPORT shutdown
                while [ -x /proc/${PID} ]
                do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
    restart)
        $0 stop
        $0 start
        ;;
    *)
        echo "Usage: $0 {start|stop|restart}"
        exit
esac

redis-sentinel:

#!/bin/sh
#
# chkconfig: 2345 55 25
# description: Redis server daemon
#
# processname: redis_6379 #需要修改与$port相同
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=26379   # 需要修改与$port相同
BINPATH=/usr/local/redis/bin
EXEC=${BINPATH}/redis-sentinel
CLIEXEC=${BINPATH}/redis-cli
PIDFILE=/data/redis/run/sentinel_${REDISPORT}.pid # pid file created by sentinel as configured in the configuation file below.
CONF="/data/redis/conf/redis-conf/sentinel_${REDISPORT}.conf"
case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
                echo "$PIDFILE exists, process is already running or crashed"
        else
                echo "Starting Redis $REDISPORT ..."
                $EXEC $CONF
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $CLIEXEC -p $REDISPORT shutdown
                while [ -x /proc/${PID} ]
                do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
    restart)
        $0 stop
        $0 start
        ;;
    *)
        echo "Usage: $0 {start|stop|restart}"
        exit
esac

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值