Redis啓動腳本,開機自動啓動

# chkconfig:   2345 90 10redis

# description:  Redis is a persistent key-value databaseide

 

PATH=$PATH:/usr/local/redis/bin:/sbin:/usr/bin:/binrest

 

REDISPORT=6379server

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

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

PASS=chbin123 io

PIDFILE=/var/run/redis_6379.pidclass

CONF="/usr/local/redis/etc/redis.conf"cli

 

case "$1" inservice

    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 -a $PASS -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


-----------------------------



添加redis服務開機啓動:

chmod +x /etc/init.d/redis


啓動redis服務:

service redis start

檢查服務是否啓動

ps -ef | grep redis

netstat -anptu | grep 6379

相關文章
相關標籤/搜索