Last active
December 20, 2015 20:59
-
-
Save sydcanem/6194370 to your computer and use it in GitHub Desktop.
Mongo db repair
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
LOCK_FILE=/var/lib/mongodb/mongo.lock | |
PID_FILE=/var/run/mongo.pid | |
DAEMON=/usr/local/bin/mongod | |
DBPATH=/var/lib/mongodb | |
mongo_running=0 | |
if [ -f $PID_FILE ]; then | |
pid=`cat $PID_FILE` | |
ps auxww | egrep "root +$pid" > /dev/null | |
if [ $? == 0 ]; then | |
mongo_running=1 | |
fi | |
fi | |
if [ $mongo_running == 1 ]; then | |
echo "Mongo already running pid:$pid" | |
exit 0 | |
fi | |
echo "Mongo is not running. Starting to repair." | |
if [ -f $LOCK_FILE ]; then | |
echo -n "Removing lock_file:$LOCK_FILE..." | |
rm $LOCK_FILE | |
echo "done." | |
fi | |
echo "Repairing mongo db at $DBPATH..." | |
$DAEMON --dbpath $DBPATH --repair | |
echo "done." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment