redis起動設定

2070 ワード

詳細


1、  :  ,redis
vi /etc/init.d/redis
#!/bin/sh
#chkconfig: 2345 80 90
#description:auto_run
PATH=/usr/local/bin:/usr/local/redis/bin:/sbin:/usr/bin:/bin  
REDISPORT=6379  
EXEC=/usr/local/redis/bin/redis-server  
REDIS_CLI=/usr/local/redis/bin/redis-cli  
PIDFILE=/var/run/redis.pid  
CONF="/usr/local/redis/etc/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  
2、       redis,  /etc/init.d/  
chmod 755 /etc/init.d/redis
3、    
chkconfig redis on
4、  ,  redis
    1. service redis start   #   /etc/init.d/redis start  
    2. service redis stop   #   /etc/init.d/redis stop