#!/bin/bash
#Developed By: Vaibhav K
# Script to set Thread count 0 for Job

PARABLU_CONFIG_SCRIPT_PATH=../config/parablu_config.sh
PARABLU_COMPONENT_CONFIG_SCRIPT_PATH=../config/parablu_component_config.sh

source $PARABLU_CONFIG_SCRIPT_PATH
source $PARABLU_COMPONENT_CONFIG_SCRIPT_PATH

function service_stop_status ()
{

if [[ "$SERVER_TYPE" == "0" ]] || [[ "$SERVER_TYPE" == "1 2" ]] || [[ "$SERVER_TYPE" == "2" ]];then 
        echo 'use parablu001

db.PRIVACY_GATEWAY.find({"gatewayName" : "GATEWAY_NAME"}).forEach(function(e) {print("SERVICESTOP=" +e.isActive)})' >capture_servicestop.js

        sed -i "s|GATEWAY_NAME|$BLUKRYPT_IP|g" capture_servicestop.js

        sudo mongo $DB1_IP:$MONGODB_PORT -u "neil" -p "parablu" --authenticationDatabase "admin" < capture_servicestop.js > capture_servicestop

        SERVICESTOP=`grep "SERVICESTOP" capture_servicestop`
        BK_ACTIVE=$( echo $SERVICESTOP | sed -e 's/SERVICESTOP=//')

else
        BK_ACTIVE=true
fi

}


if [ "$BK_ACTIVE" == "true" ]; then

	UNIQUE_GATEWAY="$BLUKRYPT_IP"
	cp job_disable.js job_disable_install.js

	sleep 1s
	sed -i "s|GATEWAY_NAME|$UNIQUE_GATEWAY|" job_disable_install.js

	sudo mongo $DB1_IP:$MONGODB_PORT -u "neil" -p "parablu" --authenticationDatabase "admin" < job_disable_install.js

	service tomcat-job1 restart
	curl -k -X POST https://$BLUKRYPT_IP/BluKryptBuilder/cloud/$CLOUD_NAME/updateProperties/

else
        echo "BLUKRYPT DISABLED. NO ACTION PERFORMED"
fi
