0

Yesterday I have upgraded my Ubuntu 14.10 to 15.04. But which lead me to stop my work. I was working on chicagoboss and mongodb. i saw error that mongodb has crashed. By typing just mongo got following error:

$ mongo
MongoDB shell version: 2.4.10
connecting to: test
Mon May 11 11:26:32.985 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145
exception: connect failed

Followed stackoverflow query and removed .lock file. Then tried to repair using

$sudo mongod --repair 

Then got an error:

*********************************************************************
 ERROR: dbpath (/data/db/) does not exist.
 Create this directory or give existing directory in --dbpath.
 See http://dochub.mongodb.org/core/startingandstoppingmongo
*********************************************************************

I observed that in my mongodb.conf file dbpath is /var/lib/mongodb. Which is correct where I found all my mongodb databases.So I tried to set dbpath to the same location but getting error:

$ mongod --dbpath "/var/lib/mongodb"
Mon May 11 11:33:18.607 [initandlisten] MongoDB starting : pid=4450 port=27017 dbpath=/var/lib/mongodb 64-bit host=laxmikant-alphonso
Mon May 11 11:33:18.607 [initandlisten] db version v2.4.10
Mon May 11 11:33:18.607 [initandlisten] git version: e3d78955d181e475345ebd60053a4738a4c5268a
Mon May 11 11:33:18.607 [initandlisten] build info: Linux ip-10-2-29-40 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_49
Mon May 11 11:33:18.607 [initandlisten] allocator: tcmalloc
Mon May 11 11:33:18.607 [initandlisten] options: { dbpath: "/var/lib/mongodb" }
Mon May 11 11:33:18.607 [initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /var/lib/mongodb/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
Mon May 11 11:33:18.607 dbexit: 
Mon May 11 11:33:18.607 [initandlisten] shutdown: going to close listening sockets...
Mon May 11 11:33:18.607 [initandlisten] shutdown: going to flush diaglog...
Mon May 11 11:33:18.607 [initandlisten] shutdown: going to close sockets...
Mon May 11 11:33:18.607 [initandlisten] shutdown: waiting for fs preallocator...
Mon May 11 11:33:18.607 [initandlisten] shutdown: lock for final commit...
Mon May 11 11:33:18.607 [initandlisten] shutdown: final commit...
Mon May 11 11:33:18.607 [initandlisten] shutdown: closing all files...
Mon May 11 11:33:18.608 [initandlisten] closeAllFiles() finished
Mon May 11 11:33:18.608 [initandlisten] shutdown: removing fs lock...
Mon May 11 11:33:18.608 [initandlisten] couldn't remove fs lock errno:9 Bad file descriptor
Mon May 11 11:33:18.608 dbexit: really exiting now

How can I resolve this issue. I want all my databases back.

Also I checked that I'm getting following error for service start:

$ sudo service mongodb start
Failed to start mongodb.service: Unit mongodb.service failed to load: No such file or directory.
Community
  • 1
  • 1
trex
  • 3,848
  • 4
  • 31
  • 54

1 Answers1

1
$ mongod --dbpath "/var/lib/mongodb"

In that case, you start mongodb as yourself. And you probably don't have R/W permission on the data directory.

$ sudo service mongodb start

Now you start mongodb as a service and it will probably change its identity from root to "mongo" or something like that. On debian-like system, the configuration for mongodb is in /etc/init/mongodb.conf or preferably in /etc/mongodb.conf. See http://packages.ubuntu.com/utopic/amd64/mongodb-server/filelist. There you can change the database path.

BTW, check the permissions for your data directory. The user "mongo"-or-whatever should have write access there:

$ ls -l /var/lib/mongodb
Community
  • 1
  • 1
Sylvain Leroux
  • 50,096
  • 7
  • 103
  • 125
  • I thought so, since I have given permissions to that `/var/lib/mongodb` directory `sudo chown -R mongodb:mongodb *` and `sudo chmod -R *`. Still not working – trex May 11 '15 at 06:27
  • @trex And the db path in /etc/mongodb.conf is correct ? You should take a look at /var/log/syslog may you will have some detailed explanations about how/why the _service_ didn't start. As of no, this is all I can say. Maybe someone else will have an other idea... – Sylvain Leroux May 11 '15 at 06:28
  • SylvainLeroux - Yes. correct. `/etc/mongodb.conf` Let me check syslog.Thanks for your efforts – trex May 11 '15 at 06:30
  • @trex I will probably not have time to look further at that. But, as you are using `systemd` on your system, you can access the log par unit ("service") by using `journalctl -u mongodb.service`. – Sylvain Leroux May 11 '15 at 06:47
  • Thanks for your valuable time. I'll check that ahead. – trex May 11 '15 at 06:54