Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.5 kB
2
Indexable
Never
#!/bin/bash
source ~/.bash_profile

setEnv () {
    LOC="$0"
    SCRIPT_HOME=$(dirname "$LOC")
    ANALYTICS_HOME=/app/server/tibenrichedODSDataConsumer
}

setEnv

# Exporting python path
export PYTHON_HOME=/app/software/binaries/python3.7.3
#export PYTHON_HOME=/home/hobapp/.local
echo $PYTHON_HOME
if [ -z ${PYTHON_HOME} ]; then
    echo -e "PYTHON_HOME variable not set.\nTerminating setup..."
    exit 1
fi;

echo "Starting Rest Data Services"
export PYTHONHOME=${PYTHON_HOME}
export ODSDATACONSUMERDEPLOYMENT=/app/server/tibenrichedODSDataConsumer/deployments
export ODSDATACONSUMERMSLOGPATH=/app/server/tibenrichedODSDataConsumer/logs
export ODSDATACONSUMERMSPATH=${PYTHONHOME}/lib/python3.7/site-packages/tibenrichedODSDataConsumer

echo "ODSDATACONSUMERDEPLOYMENT: $ODSDATACONSUMERDEPLOYMENT"
echo "ODSDATACONSUMERMSLOGPATH : $ODSDATACONSUMERMSLOGPATH"
echo "ODSDATACONSUMERMSPATH    : $ODSDATACONSUMERMSPATH"

ARTIFACT=$(find $ODSDATACONSUMERDEPLOYMENT -name *.whl | awk -F '/' '{print $NF}')
echo "ARTIFACT                 : $ARTIFACT"

runningprocess=`ps -ef  | grep 'tibenrichedODSDataConsumer/kafkaConsumerService.py' | grep 'python3' | awk '{print $2}'`
for i in $runningprocess
do
    `kill -9 $i`
done 

if [ -f ${ODSDATACONSUMERMSLOGPATH}/tibenrichedODSDataConsumer_console.log ]; then
    echo `mv $ODSDATACONSUMERMSLOGPATH/tibenrichedODSDataConsumer_console.log $ODSDATACONSUMERMSLOGPATH/tibenrichedODSDataConsumer_console.log.$(date "+%Y%m%d%H%M%S")`
else
    echo "Previous log not found. ${ODSDATACONSUMERMSLOGPATH}/tibenrichedODSDataConsumer_console.log"
fi;

process=$1
if [ "$process" == "setup" ]; then
    echo "Set up in progress"
    pip3 install $ODSDATACONSUMERDEPLOYMENT/$ARTIFACT
elif [ "$process" = "restart" ]; then
    echo "Restarting the service"
else
    echo "Argument setup or restart needs to be passed"
    exit 1
fi

python3.7 -m tibenrichedODSDataConsumer.start
echo "Checking for errors."
sleep 2
if [ -f ${ODSDATACONSUMERMSLOGPATH}/tibenrichedODSDataConsumer_console.log ]; then
    errCount=`grep -i "errno" $ODSDATACONSUMERMSLOGPATH/tibenrichedODSDataConsumer_console.log | wc -l`
    echo "Errors: ${errCount}"
    if [ ${errCount} -ge 1 ]; then
        echo `tail -10 $ODSDATACONSUMERMSLOGPATH/tibenrichedODSDataConsumer_console.log`
        echo "Error during startup."
        exit 1
    fi;
    echo "Service successfully started."
else
    echo "Service not started."
    exit 1
fi;
exit 0