Watch keynotes and sessions from MongoDB.live, our virtual developer conference.

MongoDB service autostart failed on Ubuntu 18.04

Hi All,

We have install mongodb in Ubuntu 18.04 LTS. The system was working fine. mongodb service was auto started during reboot.

We ran
sudo mongod --repair , After this the mongod service is not autostarting and

  1. sudo systemctl enable mongod
  2. sudo systemctl start mongod is not working
    But When I execute sudo mongod --config /etc/mongodb.conf, Mongo db works well.

We want to autostart mongodb using systemctl. Kindly guide me to fix the auto start issue.

Regards,
Bala

You have a few places to look for information.

First off systemctl status mongod may have some useful messages .
Next you have journalctl -u mongod.
If mongod managed to start up enough to start logging then you will find additional logs in /var/log/mongod

This mostly assume installation and default(ish) config from the official mongodb repository and packages.

This is likely your issue, mongod will usually run under the account mongodb. If you have run it via sudo some files and or directories are owned by root. One of the above commands will produce logs to that effect.

You will have to recursively change ownership of the datadirectory and the log directory.
chown -R mongodb: /var/lib/mongodb /var/log/mongodb

1 Like

Hi @bala_murugan
one word of warning: even when it sounds so simple to run the mongod as root. This will “fix” your problems only for short. It is absolutely not recommended to run mongod as root. Please follow the hints from Chris.
Michael

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.