#!/bin/sh
#
### BEGIN INIT INFO
# Provides:          mengdodo
# Required-Start:    $local_fs $network
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: redis service
# Description:       redis service daemon
### END INIT INFO
#
# chkconfig: 2345 10 90
# description: Start and Stop redis
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

REDISPORT=6379
#EXEC=/usr/local/bin/redis-server
#CLIEXEC=/usr/local/bin/redis-cli
EXEC=/www/webservice/redis-3.2.8/src/redis-server
CLIEXEC=/www/webservice/redis-3.2.8/src/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid
#CONF="/etc/redis/${REDISPORT}.conf"
CONF="/etc/redis/redis.conf"

case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
                echo "报告老板:海天盛筵大美女开始上钟了"
        else
                echo "报告老板:正在呼唤大美女队列,你马上就可以啪啪啪了……(切记必须sudo运行,否则没有pid文件产生)"
                $EXEC $CONF
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "报告老板:队列妹子压根不在,所以redis早就停止了!"
        else
                PID=$(cat $PIDFILE)
                echo "redis正在关闭中……"
                $CLIEXEC -p $REDISPORT shutdown
                while [ -x /proc/${PID} ]
                do
                    echo "报告老板:三陪女redis正在收集她的作案工具,准备打包走人……"
                    sleep 1
                done
                echo "报告老板:海天盛宴绿茶婊redis已经走了,下次再战!"
        fi
        ;;
    restart|force-reload)
        ${0} stop
        ${0} start
        ;;
    status)
        EXIST=`ps -ef | grep ${EXEC} | grep -v grep | awk '{print $2}' | xargs`
        if [ -z ${EXIST} ]
        then
                echo "报告老板:队列没有运行. "
                return 0
        else
                echo "报告老板:队列正在运行."
                return 1
        fi
        ;;
    *)
        echo "报告老板:给定的参数有start,stop,restart,status"
        ;;
esac
设置开机自动启动,关机自动关闭
     sudo update-rc.d redis-server defaults
启动Redis:
     sudo /etc/init.d/redis-server start