Skip to content

Instantly share code, notes, and snippets.

@chsh
Created September 25, 2011 04:12
Show Gist options
  • Save chsh/1240220 to your computer and use it in GitHub Desktop.
Save chsh/1240220 to your computer and use it in GitHub Desktop.
mongo repair script
#!/bin/bash
LOCK_FILE=/opt/var/db/mongodb/mongod.lock
PID_FILE=/var/run/mongo.pid
DAEMON=/opt/mongodb/bin/mongod
DBPATH=/opt/var/db/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