#! /bin/bash
# /etc/init.d/omflow_server
# chkconfig: 35 99 1

RED='\033[0;31m'
LIGHT_RED='\033[1;31m'
LIGHT_GREEN='\033[1;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
APACHE_SERVICE=/opt/omflow/apache/bin/apachectl
BoosterAgent=/opt/omflow/BoosterAgent/booster_agent
Server=/opt/omflow/server/omflow_server

case "$1" in
    start)
         status=$(ps aux | grep '[o]pt/omflow/BoosterAgent/booster_agent' | awk '{print $2}')
         if [[ -z $status ]] ;then
            echo -e "${LIGHT_GREEN}Starting BoosterAgent...${NC}"
            $BoosterAgent > /dev/null 2>&1 &
            echo -e "${YELLOW}---------------------------------------------------------"
            echo -e "${YELLOW}Please enter omflow_server status"
            echo -e "${YELLOW}Check omflow_server status."
            echo -e "${YELLOW}-------------------Install Success-----------------------${NC}"
        else
            echo -e "BoosterAgent is already ${LIGHT_GREEN}[RUNNING]${NC}"
        fi
    exit
    ;;
    stop)
        echo -e "${RED}Stopping BoosterAgent...${NC}"
        kill -9 $(ps aux | grep '[o]pt/omflow/BoosterAgent/booster_agent' | awk '{print $2}') > /dev/null 2>&1 &
        $Server stop
    ;;
    status)
        status=$(ps aux | grep '[o]pt/omflow/BoosterAgent/booster_agent' | awk '{print $2}')
        if [[ -z $status ]] ;then
            echo -e "BoosterAgent is ${RED}[NOT RUNNING]${NC}"
        else
            echo -e "BoosterAgent is ${LIGHT_GREEN}[RUNNING]${NC}"
        fi
        $Server status
    ;;
    *)
        echo "Usage: /opt/omflow/BoosterAgent/omflow_booster_agent_service {start|stop|status}"
        exit 1
    ;;
esac
exit 0

