Linux Redis开机自启动

141 阅读1分钟

Linux Redis开机自启动

1.创建自启动文件

1.进入路径

cd /etc/init.d

2.创建redis

第一步vi redis

第二步

#!/bin/bash
#chkconfig: 2345 10 90
#description: Start and Stop redis

EXEC=/home/redis-5.0.4/src/redis-server 
CLIEXEC=/home/redis-5.0.4/src/redis-cli
PIDFILE=/var/run/redis_6379.pid
CONF="/home/redis-5.0.4/redis.conf"
REDISPORT="6379"

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

2.运用chkconfig 进行管理

chkconfig --add redis
chkconfig redis on

3.REBOOT