redis开机自启

作者: zianL | 来源:发表于2019-07-01 19:50 被阅读0次
#!/bin/sh  
# chkconfig: 2345 10 90  
# description: Start and Stop redis  注意每一样不要顶格
  
REDISPORT=6379  
EXEC=/usr/local/src/redis/redis-3.2.8/src/redis-server  
CLIEXEC=/usr/local/src/redis/redis-3.2.8/src/redis-cli  
  
PIDFILE=/var/run/redis_${REDISPORT}.pid  
CONF="/usr/local/src/redis/redis-3.2.8/redis.conf"  
case "$1" in  
    start)  
        if [ -f $PIDFILE ]  
        then  
                echo "$PIDFILE exists, process is already running or crashed"  
        else  
                echo "Starting Redis server..."  
                $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  
        sleep 3  
        "$0" start  
        ;;  
    *)  
        echo "Please use start or stop or restart as first argument"  
        ;;  
esac  

相关文章

网友评论

    本文标题:redis开机自启

    本文链接:https://www.haomeiwen.com/subject/wnothctx.html