#!/bin/bash

# author

#date 2015-03-12

#chkconfig: - 90 23

pidfile="/var/run/redis.pid"

#config /etc/redis/redis.conf

#source function library.

. /etc/rc.d/init.d/functions

#defualt files

redis_conf=${redis_conf:-"/etc/redis/redis.conf"}

redis=${redis_bin:-"/usr/local/bin/redis-server"}

lockfile=${lockifle:-"/var/lock/subsys/redis"}

start(){

#   echo -n "starting redis:"

   $redis $redis_conf 2>&1

    retval=$?

    echo $retval

    [$retval -eq 0] && touch $lockfile $pidfile

    return $retval

  }

stop() {

   echo -n  "stopping redis:"

   killproc  $lockfile $redis  #killporc 函数是在/etc/rc.d/init.d/functions中定义的,它的作就是关闭进程,

    retval=$?

   echo $retval

  [ $retval -eq 0 ] && rm -f $lockfile

   return $retval

  }

restart(){

  stop

  start

   }

case $1 in

start)

   start

   ;;

stop)

   stop

   ;;

restart)

   restart

   ;;

status)

   status redis

   ;;

*)

        echo $"Usage: $0 {start|stop|status|restart}"

        exit 2

esac

exit $?