#!/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_unquiesce bin path is not set"
unquiescecommand="mongo admin"
else
unquiescecommand="${binpath}/mongo admin"
echo "$(date '+%d/%m/%Y %H:%M:%S') cv_mongo_unquiesce 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_unquiesce port is set to $port"
unquiescecommand="${unquiescecommand} --port ${port}"
else
echo "$(date '+%d/%m/%Y %H:%M:%S') cv_mongo_unquiesce port is not set"
unquiescecommand="${unquiescecommand} --port 27017"
fi
#Identify if authentication is enabled
echo "$(date '+%d/%m/%Y %H:%M:%S') cv_mongo_unquiesce 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_unquiesce Authentication credentials are not set"
else
echo "$(date '+%d/%m/%Y %H:%M:%S') cv_mongo_unquiesce Authentication credentials are set $user:$password"
unquiescecommand="${unquiescecommand} -u ${user} --authenticationDatabase admin -p "'""'
fi
#Identify if ignoreMongoDBUnquiesceErrors is set
echo "$(date '+%d/%m/%Y %H:%M:%S') cv_mongo_unquiesce Check if ignoreMongoDBUnquiesceErrors is set"
ignoreMongoDBUnquiesceErrors=$(getProperty "ignoreMongoDBUnquiesceErrors")
echo "$(date '+%d/%m/%Y %H:%M:%S') cv_mongo_unquiesce Unquiescing the server"
unquiescecommand="${unquiescecommand}"' --eval "printjson(db.adminCommand( { fsyncUnlock: 1 } ))"'
echo "$(date '+%d/%m/%Y %H:%M:%S') cv_mongo_unquiesce Unquiesce command : ${unquiescecommand}"
if [[ -z $password ]];
then
eval $unquiescecommand
else
eval ${unquiescecommand}<<EOF
$password
EOF
fi
## get status ##
status=$?
echo "$(date '+%d/%m/%Y %H:%M:%S') cv_mongo_unquiesce Unquiesce command exit status is $status"
if [[ ! $status -eq 0 ]] && [[ -z ignoreMongoDBUnquiesceErrors || ignoreMongoDBUnquiesceErrors -eq 0 ]]
then
echo "$(date '+%d/%m/%Y %H:%M:%S') cv_mongo_unquiesce Unquiesce command failed"
exit 1
elif [[ ! $status -eq 0 ]] && [[ ! -z ignoreMongoDBUnquiesceErrors || ignoreMongoDBUnquiesceErrors -eq 1 ]]
then
echo "$(date '+%d/%m/%Y %H:%M:%S') cv_mongo_unquiesce ignoreMongoDBUnquiesceErrors is set to $ignoreMongoDBUnquiesceErrors"
echo "$(date '+%d/%m/%Y %H:%M:%S') cv_mongo_unquiesce Ignoring the unquiesce command failure and exiting"
exit 0
else
echo "$(date '+%d/%m/%Y %H:%M:%S') cv_mongo_unquiesce Unquiesce command exit status is $status"
fi
exit 0