Problems with MongoDB / old lock file, terminating

By ayates

After a recent server crash our MongoDB was refusing to restart, if you tail the logs:

tail -f /var/log/mongodb/mongodb.log

and you see something along the lines of:

Mon Dec 10 13:58:39 [initandlisten] exception in initAndListen std::exception: old lock file, terminating
Mon Dec 10 13:58:39 dbexit: 
Mon Dec 10 13:58:39 [initandlisten] shutdown: going to close listening sockets...
Mon Dec 10 13:58:39 [initandlisten] shutdown: going to flush diaglog...
Mon Dec 10 13:58:39 [initandlisten] shutdown: going to close sockets...
Mon Dec 10 13:58:39 [initandlisten] shutdown: waiting for fs preallocator...
Mon Dec 10 13:58:39 [initandlisten] shutdown: closing all files...
Mon Dec 10 13:58:39 closeAllFiles() finished
Mon Dec 10 13:58:39 dbexit: really exiting now

Then you can simply remove the old lock file and start MongoDB:

rm /var/lib/mongodb/mongod.lock
/etc/init.d/mongodb start

If you check the status you should see that mongo is running again:

status mongodb