I am using Django frameowrk
. My client is in js
and backend is using mongodb
. Two days back I stopped and restarted the Apache2
server and the website was running fine. Today all of a sudden the website is showing 500 Internel serve error
. When I checked the error.log
file it is showing:
[.....] ConnectionError: Cannot connect to the database:
[.....] could not connect to localhost:27017: [Errno 111] Connection refused
So, I tried to test the connection to mongodb
through python
like this:
>>> from pymongo import Connection
>>> connection = Connection('localhost',27017)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.6/dist-packages/pymongo/connection.py", line 381, in __init__
self.__find_node()
File "/usr/local/lib/python2.6/dist-packages/pymongo/connection.py", line 659, in __find_node
raise AutoReconnect(', '.join(errors))
pymongo.errors.AutoReconnect: could not connect to localhost:27017: [Errno 111] Connection refused
I also tested the connection using $mongo
and it shows:
MongoDB shell version: 2.4.9
connecting to: test
Mon Jan 20 15:22:53.729 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145
exception: connect failed
I tried to search for answers to this problem and there I saw people are telling to delete the mongod.lock
file and restart the mongodb like here Pymongo keeps refusing the connection at 27017 and MongoDB won't start after server crash but here it is written : http://docs.mongodb.org/manual/tutorial/recover-data-following-unexpected-shutdown/ In normal operation, you should never remove the mongod.lock file and start mongod. Instead consider the one of the above methods to recover the database and remove the lock files. In dire situations you can remove the lockfile, and start the database using the possibly corrupt files, and attempt to recover data from the database; however, it’s impossible to predict the state of the database in these situations.
I am really confused on what to do? Should I remove the mongod.lock
file or not? Also, do I first need to start the mongodb
server and then start the apache2
server? Mongodb log file shows:
tail -n -30 mongodb.log
***** SERVER RESTARTED *****
Mon Jan 20 15:10:19.740 [initandlisten] MongoDB starting : pid=8061 port=27017 dbpath=/var/lib/mongodb 64-bit host=hand
Mon Jan 20 15:10:19.740 [initandlisten] db version v2.4.9
Mon Jan 20 15:10:19.740 [initandlisten] git version: xxxxx //gives the number
Mon Jan 20 15:10:19.740 [initandlisten] build info: xxxx
Mon Jan 20 15:10:19.740 [initandlisten] allocator: tcmalloc
Mon Jan 20 15:10:19.740 [initandlisten] options: { config: "/etc/mongodb.conf", dbpath: "/var/lib/mongodb", logappend: "true", logpath: "/var/log/mongodb/mongodb.log" }
Mon Jan 20 15:10:19.742 [initandlisten] journal dir=/var/lib/mongodb/journal
Mon Jan 20 15:10:19.742 [initandlisten] recover : no journal files present, no recovery needed
Mon Jan 20 15:10:19.742 [initandlisten]
Mon Jan 20 15:10:19.742 [initandlisten] ERROR: Insufficient free space for journal files
Mon Jan 20 15:10:19.742 [initandlisten] Please make at least 3379MB available in /var/lib/mongodb/journal or use --smallfiles
Mon Jan 20 15:10:19.742 [initandlisten]
Mon Jan 20 15:10:19.743 [initandlisten] exception in initAndListen: 15926 Insufficient free space for journals, terminating
Mon Jan 20 15:10:19.743 dbexit:
Mon Jan 20 15:10:19.743 [initandlisten] shutdown: going to close listening sockets...
Mon Jan 20 15:10:19.743 [initandlisten] shutdown: going to flush diaglog...
Mon Jan 20 15:10:19.743 [initandlisten] shutdown: going to close sockets...
Mon Jan 20 15:10:19.743 [initandlisten] shutdown: waiting for fs preallocator...
Mon Jan 20 15:10:19.743 [initandlisten] shutdown: lock for final commit...
Mon Jan 20 15:10:19.743 [initandlisten] shutdown: final commit...
Mon Jan 20 15:10:19.743 [initandlisten] shutdown: closing all files...
Mon Jan 20 15:10:19.743 [initandlisten] closeAllFiles() finished
Mon Jan 20 15:10:19.743 [initandlisten] journalCleanup...
Mon Jan 20 15:10:19.743 [initandlisten] removeJournalFiles
Mon Jan 20 15:10:19.743 [initandlisten] shutdown: removing fs lock...
Mon Jan 20 15:10:19.743 dbexit: really exiting now
If I run the following command it shows:
$ sudo service mongodb start
Starting database: mongodb failed!