redis配置为开机自启动

将redis设置为系统服务,并且开机自启动。需要完成以下脚本。

#!/bin/sh

# chkconfig: 2345 10 90

# description: Start and Stop redis

PATH=/usr/local/bin:/sbin:/usr/bin:/bin

REDISPORT=6379

扫描二维码关注公众号,回复: 585645 查看本文章

EXEC=/usr/local/bin/redis-server

REDIS_CLI=/usr/local/bin/redis-cli

PIDFILE=/var/run/redis.pid

CONF="/usr/local/src/redis-2.6.4/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

        if [ "$?"="0" ]

        then

              echo "Redis is running..."

        fi

        ;;

    stop)

        if [ ! -f $PIDFILE ]

        then

                echo "$PIDFILE does not exist, process is not running"

        else

                PID=$(cat $PIDFILE)

                echo "Stopping ..."

                $REDIS_CLI -p $REDISPORT SHUTDOWN

                while [ -x ${PIDFILE} ]

               do

                    echo "Waiting for Redis to shutdown ..."

                    sleep 1

                done

                echo "Redis stopped"

        fi

        ;;

   restart|force-reload)

        ${0} stop

        ${0} start

        ;;

  *)

    echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2

        exit 1

esac

注意标红的虽然是注释,但是还是需要存在才成。当然,path路径以及redis安装路径,随个人安装情况不同而变。

放到/etc/init.d/下 文件名redis,chomd 755 redis

chkconfig redis on即可。

猜你喜欢

转载自yuri-liuyu.iteye.com/blog/1935612
今日推荐