Mongo can't start service

16,021

I was able to reproduce your issue by setting the wrong ownership on the folder /var/log/mongodb:

root@demo:~# ls -lh /var/log/mongodb/
total 512
-rw-r--r-- 1 root root 0 Jan 22 17:57 mongod.log
root@demo:~# systemctl restart mongod
root@demo:~# systemctl status mongod
● mongod.service - MongoDB Database Server
   Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2019-01-22 17:57:13 UTC; 2s ago
     Docs: https://docs.mongodb.org/manual
  Process: 795 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=1/FAILURE)
 Main PID: 795 (code=exited, status=1/FAILURE)

Jan 22 17:57:13 demo systemd[1]: Started MongoDB Database Server.
Jan 22 17:57:13 demo systemd[1]: mongod.service: Main process exited, code=exited, status=1/FAILURE
Jan 22 17:57:13 demo systemd[1]: mongod.service: Unit entered failed state.
Jan 22 17:57:13 demo systemd[1]: mongod.service: Failed with result 'exit-code'.

Try correcting the ownership of the MongoDB logging and data directories:

root@demo:~# chown -Rc mongodb. /var/log/mongodb
changed ownership of '/var/log/mongodb/mongod.log' from root:root to mongodb:nogroup
changed ownership of '/var/log/mongodb' from root:root to mongodb:nogroup
root@demo:~# chown -Rc mongodb. /var/lib/mongodb
root@demo:~# systemctl restart mongod
root@demo:~# systemctl status mongod
● mongod.service - MongoDB Database Server
   Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
   Active: active (running) since Tue 2019-01-22 17:58:30 UTC; 1s ago
     Docs: https://docs.mongodb.org/manual
 Main PID: 802 (mongod)
   CGroup: /system.slice/mongod.service
           └─802 /usr/bin/mongod --config /etc/mongod.conf

Jan 22 17:58:30 demo systemd[1]: Started MongoDB Database Server.

If this doesn't work, try reinstalling MongoDB, deleting all existing data:

sudo apt purge mongodb-org mongodb-org-mongos mongodb-org-server mongodb-org-shell mongodb-org-tools
sudo rm -rfv /etc/mongod.conf /var/log/mongodb /var/lib/mongodb
sudo find /tmp -type s -iname '*mongodb*' -delete
sudo apt install mongodb-org
Share:
16,021
Viktor Kushnir
Author by

Viktor Kushnir

Updated on September 18, 2022

Comments

  • Viktor Kushnir
    Viktor Kushnir over 1 year

    I have Ubuntu 16.04. And reinstall mongobd following tutorial on oficial mongo site - https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/ As result i have: mongo -version

    MongoDB shell version v4.0.5
    git version: 3739429dd92b92d1b0ab120911a23d50bf03c412
    OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
    allocator: tcmalloc
    modules: none
    build environment:
        distmod: ubuntu1604
        distarch: x86_64
        target_arch: x86_64
    

    But I cant start mongodb((

    sudo systemctl status mongodb
    ● mongodb.service - High-performance, schema-free document-oriented database
       Loaded: loaded (/etc/systemd/system/mongodb.service; disabled; vendor preset: enabled)
       Active: failed (Result: exit-code) since Tue 2019-01-22 16:27:13 UTC; 10s ago
      Process: 29736 ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf (code=exited, status=1/FAILURE)
     Main PID: 29736 (code=exited, status=1/FAILURE)
    
    Jan 22 16:27:13 mahumachinen systemd[1]: Started High-performance, schema-free document-oriented database.
    Jan 22 16:27:13 mahumachinen systemd[1]: mongodb.service: Main process exited, code=exited, status=1/FAILURE
    Jan 22 16:27:13 mahumachinen systemd[1]: mongodb.service: Unit entered failed state.
    Jan 22 16:27:13 mahumachinen systemd[1]: mongodb.service: Failed with result 'exit-code'.
    

    Please help!

    • Deltik
      Deltik over 5 years
      One thing that stands out to me is that you are referring to mongodb.service, but if you followed the instructions you linked, the service is actually mongod.service. You might be able to figure out the cause of the service failure in /var/log/mongodb/mongod.log (unless you changed the logging path in /etc/mongod.conf).
    • Viktor Kushnir
      Viktor Kushnir over 5 years
      Thank you, probably i made somewhere mistake, I made several instalations from different tuturials. now /var/log/mongodb/mongod.log is empty. although systemLog: destination: file logAppend: true path: /var/log/mongodb/mongod.log
    • Viktor Kushnir
      Viktor Kushnir over 5 years
      $ sudo service mongod start Failed to start mongod.service: Unit mongod.service not found. $ sudo systemctl unmask mongodb $ sudo service mongod start
    • Viktor Kushnir
      Viktor Kushnir over 5 years
      sudo service mongod status ● mongod.service - MongoDB Database Server Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Tue 2019-01-22 17:19:43 UTC; 6s ago
    • Viktor Kushnir
      Viktor Kushnir over 5 years
      sudo /usr/bin/mongod --quiet --config /etc/mongod.conf helps me. Thank you, but whats happens?
  • Viktor Kushnir
    Viktor Kushnir over 5 years
    Tried correcting the ownership of the MongoDB logging and data directories, but it did not help, reinstalled, but also did not help.
  • Viktor Kushnir
    Viktor Kushnir over 5 years
    Now again Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Tue 2019-01-22 18:45:00 UTC; 7s ago Docs: docs.mongodb.org/manual Process: 31469 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=100) Main PID: 31469 (code=exited, status=100)
  • Deltik
    Deltik over 5 years
    @ViktorKushnir: What's the log file showing now?
  • Viktor Kushnir
    Viktor Kushnir over 5 years
    log file is empty now
  • Viktor Kushnir
    Viktor Kushnir over 5 years
    After reinstall: $ sudo systemctl start mongod Failed to start mongod.service: Unit mongod.service not found.
  • Deltik
    Deltik over 5 years
    @ViktorKushnir: I do not see how this is possible if you're following the installation instructions in the official documentation. The /lib/systemd/system/mongod.service file comes from the mongodb-org-server package.
  • Viktor Kushnir
    Viktor Kushnir over 5 years
    Yes, its very strange(((
  • Viktor Kushnir
    Viktor Kushnir over 5 years
    hi! Please I need your help! I stiil have a problem with mongo(( Finally I have the same story like here: stackoverflow.com/questions/45691032/… But all answers dont helps me.
  • Deltik
    Deltik over 5 years
    @ViktorKushnir: Run sudo -u mongodb strace -vfts1000 /usr/bin/mongod --config /etc/mongod.conf and paste as much output as you can to a pastebin (such as Pastebin.com) starting from the beginning.
  • Viktor Kushnir
    Viktor Kushnir over 5 years
  • Viktor Kushnir
    Viktor Kushnir over 5 years
    $ /usr/bin/mongod --verbose --config /etc/mongod.conf & [1] 28904 $ 2019-01-23T16:10:36.190+0000 F CONTROL [main] Failed global initialization: FileNotOpen: Failed to open "/var/log/mongodb/mongod.log"
  • Viktor Kushnir
    Viktor Kushnir over 5 years
    $ ls -la /var/log/ | grep mongo drwxr-xr-x 2 mongodb mongodb 4096 Jan 23 15:34 mongodb
  • Deltik
    Deltik over 5 years
    @ViktorKushnir: Remove the file /tmp/mongodb-27017.sock, which currently has the wrong permissions. That's what the strace indicates is the "Fatal Assertion".
  • Viktor Kushnir
    Viktor Kushnir over 5 years
    Man, you are great! Although I tried it before, but now it worked! Thank you more!!!
  • Deltik
    Deltik over 5 years
    @ViktorKushnir: I updated the answer to include removing the socket. If you're good to go, please check the gray check mark by my answer to indicate that you accepted it.
  • Viktor Kushnir
    Viktor Kushnir over 5 years
    I marked the check, but cant vote(( - prntscr.com/mb5ydf
  • varshneydevansh
    varshneydevansh over 3 years
    Thank You so much. I have tried all the stuff that I can do and find but this is the last post which just helped me.
  • alper
    alper over 2 years
    reinstalling MongoDB solved my issue. After reinstalling should I apply sudo chown -Rc mongodb. /var/lib/mongodb?
  • Deltik
    Deltik over 2 years
    Sounds like you didn't need to. I don't expect it to hurt if you do the chown.