shell script - check mongod server is running
You should be able to create a bash script like this:
mongo --eval "db.stats()" # do a simple harmless command of some sort
RESULT=$? # returns 0 if mongo eval succeeds
if [ $RESULT -ne 0 ]; then
echo "mongodb not running"
exit 1
else
echo "mongodb running!"
fi
try running this in your shell script:-
pgrep mongod
If the value is numeric you know that the process is running, if you get an empty value, flag it as service not running...