#!/bin/bash
#
# onapp-redis This script manages Redis server
#
# chkconfig:       - 88 13
# description:     Wrapper over Redis init script \
# which returns exit codes, unacceptable for Pacemaker
# Source onapp functions
. /onapp/interface/script/init/onapp_functions.sh
REDIS_SENTINEL=/etc/init.d/redis-sentinel

normalize(){
    exit_code=$1

    if [ "x$exit_code" = "x0" ]; then
        return 0
    else
        return 1
    fi
}

usage(){
    generic_usage
}

start(){
    if pgrep redis > /dev/null; then
        return 1
    else
        ${REDIS_SENTINEL} start
        normalize $?
    fi
}

stop(){
    if pgrep redis > /dev/null; then
        ${REDIS_SENTINEL} stop
        normalize $?
    else
        return 1
    fi
}

restart(){
    ${REDIS_SENTINEL} restart
    normalize $?
}

status(){
    ${REDIS_SENTINEL} status
    normalize $?
}

case "$1" in
  status)
        status
        ;;
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        restart
        ;;
  *)
        usage
        ;;
esac
