Thursday 3 March 2016

MongoDB won't start - ERROR: dbpath (/data/db) does not exist.

For some reason - due to a bug probably - mongodb (or mongod) database won't start on default install because it is referencing the running direction /data/db to create a lock file. This error occurs even if you set the dbpath in /etc/mongod.conf to somewhere else (default installation says: /var/lib/mongodb). To fix this, simply create a simlink or the directory /data/db itself!
# service mongod start
Redirecting to /bin/systemctl start  mongod.service
Job for mongod.service failed because the control process exited with error code. See "systemctl status mongod.service" and "journalctl -xe" for details.
# systemctl status mongod.service
● mongod.service - High-performance, schema-free document-oriented database
   Loaded: loaded (/usr/lib/systemd/system/mongod.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Thu 2016-03-03 09:50:01 GMT; 6s ago
  Process: 21502 ExecStart=/usr/bin/mongod $OPTIONS run (code=exited, status=45)

Mar 03 09:50:01 p0 systemd[1]: Starting High-performance, schema-free document-oriented database...
Mar 03 09:50:01 p0 mongod[21502]: about to fork child process, waiting until server is ready for connections.
Mar 03 09:50:01 p0 mongod[21502]: forked process: 21504
Mar 03 09:50:01 p0 mongod[21502]: ERROR: child process failed, exited with error number 45
Mar 03 09:50:01 p0 systemd[1]: mongod.service: control process exited, code=exited status=45
Mar 03 09:50:01 p0 systemd[1]: Failed to start High-performance, schema-free document-oriented database.
Mar 03 09:50:01 p0 systemd[1]: Unit mongod.service entered failed state.
Mar 03 09:50:01 p0 systemd[1]: mongod.service failed.

# mongod --repair
2016-03-03T09:55:49.905+0000 [initandlisten] MongoDB starting : pid=21520 port=27017 dbpath=/data/db 64-bit host=comp-sscm-p0
2016-03-03T09:55:49.906+0000 [initandlisten] db version v2.6.11
2016-03-03T09:55:49.906+0000 [initandlisten] git version: nogitversion
2016-03-03T09:55:49.906+0000 [initandlisten] OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
2016-03-03T09:55:49.906+0000 [initandlisten] build info: Linux buildvm-08.phx2.fedoraproject.org 4.1.4-100.fc21.x86_64 #1 SMP Tue Aug 4 03:25:05 UTC 2015 x86_64 BOOST_LIB_VERSION=1_53
2016-03-03T09:55:49.906+0000 [initandlisten] allocator: tcmalloc
2016-03-03T09:55:49.906+0000 [initandlisten] options: { repair: true }
2016-03-03T09:55:49.906+0000 [initandlisten] exception in initAndListen: 10296
*********************************************************************
 ERROR: dbpath (/data/db) does not exist.
 Create this directory or give existing directory in --dbpath.
 See http://dochub.mongodb.org/core/startingandstoppingmongo
*********************************************************************
, terminating
2016-03-03T09:55:49.906+0000 [initandlisten] dbexit:
2016-03-03T09:55:49.906+0000 [initandlisten] shutdown: going to close listening sockets...
2016-03-03T09:55:49.906+0000 [initandlisten] shutdown: going to flush diaglog...
2016-03-03T09:55:49.906+0000 [initandlisten] shutdown: going to close sockets...
2016-03-03T09:55:49.906+0000 [initandlisten] shutdown: waiting for fs preallocator...
2016-03-03T09:55:49.906+0000 [initandlisten] shutdown: closing all files...
2016-03-03T09:55:49.906+0000 [initandlisten] closeAllFiles() finished
2016-03-03T09:55:49.906+0000 [initandlisten] dbexit: really exiting now

# mkdir /data
# ln -s /var/lib/mongodb /data/db
or
# mkdir -p /data/db
# chown mongodb:mongodb /data/db
# service mongod start
Redirecting to /bin/systemctl start  mongod.service
# systemctl status mongod.service
● mongod.service - High-performance, schema-free document-oriented database
   Loaded: loaded (/usr/lib/systemd/system/mongod.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2016-03-03 09:58:15 GMT; 55s ago
  Process: 21863 ExecStart=/usr/bin/mongod $OPTIONS run (code=exited, status=0/SUCCESS)
 Main PID: 21865 (mongod)
   CGroup: /system.slice/mongod.service
           └─21865 /usr/bin/mongod --quiet -f /etc/mongod.conf run

Mar 03 09:58:15 p0 systemd[1]: Starting High-performance, schema-free document-oriented database...
Mar 03 09:58:15 p0 mongod[21863]: about to fork child process, waiting until server is ready for connections.
Mar 03 09:58:15 p0 mongod[21863]: forked process: 21865
Mar 03 09:58:15 p0 systemd[1]: Started High-performance, schema-free document-oriented database.
Mar 03 09:58:58 p0 systemd[1]: Started High-performance, schema-free document-oriented database.