Skip to content

Instantly share code, notes, and snippets.

@mssobhan
Created July 24, 2016 09:35
Show Gist options
  • Save mssobhan/fecaa427b263a1b6ae7e2a84f40ce873 to your computer and use it in GitHub Desktop.
Save mssobhan/fecaa427b263a1b6ae7e2a84f40ce873 to your computer and use it in GitHub Desktop.
#! /bin/bash
SCRIPT=("mongod")
PID=$(ps aux | grep -v grep | grep $SCRIPT | awk '{print $2}')
if [[ -z "$PID" ]]
then
nohup /opt/mongo30/mongodb/bin/mongod --dbpath /var/lib/mongodb/ --storageEngine wiredTiger --port 27017 &
else
#kill -9 $PID
#sleep 17
#sleep 40
echo "Successfully killed '$PID' no process. "
PID=$(ps aux | grep -v grep | grep $SCRIPT | awk '{print $2}')
if [[ -z "$PID" ]]
then
nohup /opt/mongo30/mongodb/bin/mongod --dbpath /var/lib/mongodb/ --storageEngine wiredTiger --port 27017 &
fi
PID=$(ps aux | grep -v grep | grep $SCRIPT | awk '{print $2}')
echo "Successfully started '$SCRIPT' with process no '$PID'."
fi
exit
####RUN IT in crontab entry using
###*/2 * * * * root /bin/bash /home/mohua/mongo30restarter.sh >> /home/mohua/mongo_out.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment