0

My MongoDB server is not starting on command mongod

Typing sudo service mongodb status yeilds

mongodb.service - High-performance, schema-free document-oriented database
Loaded: loaded (/etc/systemd/system/mongodb.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2017-11-28 20:08:25 IST; 2s ago
Process: ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=1/FAILURE)
Main PID: 29675 (code=exited, status=1/FAILURE)

System service:

#/etc/systemd/system/mongodb.service
[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target

[Service]
User=mongodb
Group=mongodb
ExecStart=/usr/bin/mongod --config /etc/mongod.conf

[Install]
WantedBy=multi-user.target

mongod conf:

#/etc/mongod.conf
storage:
    dbPath: /var/lib/mongodb
    journal:
        enabled: true

systemLog:
    destination: file
    logAppend: true
    path: /var/log/mongodb/mongod.log

However if i am running sudo -u mongodb mongod --config /etc/mongod.conf it runs. Also if I run sudo mongod the server tries to start but the storage path is /data/db/ which I haven't created.

mongod --config /etc/mongod.conf gives the below error

[main] Failed global initialization: FileNotOpen: Failed to open "/var/log/mongodb/mongod.log"

I had run chown -R mongodb:mongodb /var/lib/mongodb

Permissions:

-rw-r--r-- 1 mongodb mongodb  4096 Nov 28 20:19 /var/log/mongodb/mongod.log
drwxr-xr-x  4 mongodb mongodb  20480 Nov 28 21:32 /var/lib/mongodb

Now whenever I need MongoDB server I have to run it with sudo mongod --dbpath /var/lib/mongodb/

It seems like a permission issue for me. But I cannot figure how to fix this out?

Noushad
  • 6,063
  • 3
  • 25
  • 28
  • Double check the `/var/lib/mongodb` and `/var/log/mongodb` folders permissions. – Neodan Nov 28 '17 at 15:47
  • ```drwxr-xr-x 4 mongodb mongodb 20480 Nov 28 21:32 /var/lib/mongodb``` and ```drwxr-xr-x 2 mongodb mongodb 4096 Nov 28 20:19 /var/log/mongodb``` – Noushad Nov 28 '17 at 16:03
  • Maybe the lock.file? https://stackoverflow.com/questions/6857781/what-is-the-use-of-the-mongo-lock-file – Björn Nov 29 '17 at 08:59
  • @Björn Nope, the lock was not the issue. I still am struggling with the issue. Now whenever I need MongoDB server I have to run it with `sudo mongod --dbpath /var/lib/mongodb/` – Noushad Apr 16 '18 at 15:18

0 Answers0