quiesce.sh script (MongoDB)

#!/bin/sh
FILE_NAME=/opt/cv_mongodb_snap/cv_mongodb_properties
prop_value=""
user=""
password=""
function getProperty()
{
        prop_value=""
        prop_key=$1
        prop_value=$(cat ${FILE_NAME} | grep -iw ${prop_key} | cut -d'=' -f2)
        echo "${prop_value}"
}
#Identify if bin path is set
binpath=$(getProperty "bin")
if [ -z $binpath ]
then
     echo "$(date '+%d/%m/%Y %H:%M:%S')  cv_mongo_quiesce     bin path is not set"
     quiescecommand="mongo  admin"
else
     quiescecommand="${binpath}/mongo admin"
     echo "$(date '+%d/%m/%Y %H:%M:%S')  cv_mongo_quiesce     bin path is set $binpath"
fi
#Identify if host bind ip is set
host=$(getProperty "host")
if [ -z $host ]
then
     echo "$(date '+%d/%m/%Y %H:%M:%S')  cv_mongo_quiesce     Host bind IP is not set"
else
     quiescecommand="${quiescecommand} --host ${host}"
     echo "$(date '+%d/%m/%Y %H:%M:%S')  cv_mongo_quiesce     bin path is set $binpath"
fi
#Identify if port is set
port=$(getProperty "port")
if [ ! -z $port ]
then
     echo "$(date '+%d/%m/%Y %H:%M:%S')  cv_mongo_quiesce     port is set to $port"
     quiescecommand="${quiescecommand} --port ${port}"
else
     echo "$(date '+%d/%m/%Y %H:%M:%S')  cv_mongo_quiesce     port is not set"
      quiescecommand="${quiescecommand} --port 27017"
fi
#Identify if authentication is enabled
echo "$(date '+%d/%m/%Y %H:%M:%S')  cv_mongo_quiesce     Check if authentication credentials are provided"
user=$(getProperty "username")
password=$(getProperty "password")
if [[ -z $user && -z $password ]];
then
     echo "$(date '+%d/%m/%Y %H:%M:%S')  cv_mongo_quiesce     Authentication credentials are not set"
else
      echo "$(date '+%d/%m/%Y %H:%M:%S')  cv_mongo_quiesce     Authentication credentials are set for ($user)"
      quiescecommand="${quiescecommand} -u ${user} --authenticationDatabase admin -p "'""'
fi
#Identify if ignoreMongoDBQuiesceErrors is set
echo "$(date '+%d/%m/%Y %H:%M:%S')  cv_mongo_quiesce     Check if ignoreMongoDBQuiesceErrors is set"
ignoreMongoDBQuiesceErrors=$(getProperty "ignoreMongoDBQuiesceErrors")
echo "$(date '+%d/%m/%Y %H:%M:%S')  cv_mongo_quiesce     Quiescing the server " 
quiescecommand="${quiescecommand}"' --eval "printjson(db.adminCommand( { fsync: 1, lock: true } ))"'
echo "$(date '+%d/%m/%Y %H:%M:%S')  cv_mongo_quiesce     Quiesce command : ${quiescecommand}"
     if [[ -z $password ]];
       then
           eval $quiescecommand
      else
eval ${quiescecommand}<<EOF
$password
EOF
    fi
## get status ##
status=$?
echo "$(date '+%d/%m/%Y %H:%M:%S')  cv_mongo_quiesce     Quiesce command exit status is $status"
if [[ ! $status -eq 0 ]] && [[  -z ignoreMongoDBQuiesceErrors || ignoreMongoDBQuiesceErrors -eq 0 ]]
then
    echo "$(date '+%d/%m/%Y %H:%M:%S')  cv_mongo_quiesce     Quiesce command failed"
    exit 1
elif [[ ! $status -eq 0 ]] && [[ ! -z ignoreMongoDBQuiesceErrors || ignoreMongoDBQuiesceErrors -eq 1 ]]
then
    echo "$(date '+%d/%m/%Y %H:%M:%S')  cv_mongo_quiesce     ignoreMongoDBQuiesceErrors is set to $ignoreMongoDBQuiesceErrors"
    echo "$(date '+%d/%m/%Y %H:%M:%S')  cv_mongo_quiesce     Ignoring the quiesce command failure and exiting"
    exit 0
else
    echo "$(date '+%d/%m/%Y %H:%M:%S')  cv_mongo_quiesce     Quiesce command exit status is $status"
fi
exit 0

Loading...