-e #/bin/sh
 #Configurations injected by install_server below....

 EXEC=/opt/TopPatch/bin/redis-server
 CLIEXEC=/opt/TopPatch/bin/redis-cli
 PIDFILE=/opt/TopPatch/var/run/redis_6379.pid
 CONF="/opt/TopPatch/conf/6379.conf"

 REDISPORT="6379"

 ###############

 # REDHAT chkconfig header

 # chkconfig: - 58 74
 # description: redis_6379 is the redis daemon.
 ### BEGIN INIT INFO
 # Provides: redis_6379
 # Required-Start: 
 # Required-Stop: 
 # Should-Start: 
 # Should-Stop: 
 # Short-Description: start and stop redis_6379
 # Description: Redis daemon
 ### END INIT INFO



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
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $CLIEXEC -p $REDISPORT shutdown
                while [ -x /proc/${PID} ]
                do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac
