Mongodb on Ubuntu -' Main process exited, code=exited, status=1/FAILURE'

Hi @Konstantina_Arnaoutaki welcome to the community!

From what I gathered on the information so far, it appears that the main issue here is permissions and consistency, as we are seeing some files under the dbpath are owned by one user (mongodb), and some other files are owned by root. This mix of ownership implies that mongod was not consistently started under one user: one time it was run as root, other times it was not.

In addition, it appears that the file locations are also not consistent, e.g. sometimes it’s under the root directory (/data/db), sometimes it’s under other directories (/home/user/mongodb, /var/lib/mongodb or similar, among others).

One particular thing I noticed is that in your initial post, the /etc/mongod.conf file contains instructions for mongod to listen to port 23654. The existence of the file mongodb-23654.sock and also mongodb-27017.sock suggested that this was changed for some reason (as @Ramachandra_Tummala pointed out earlier). This is not the standard MongoDB port, so it’s probably best to set all settings in the config files to its default values so that there are no unexpected values to deal with in the future.

Depending on your preference, I would suggest to stick to one method of running MongoDB, be it from a service, running manually, or some other method you prefer, and keep using that method throughout. It may be easier in the long run to use the existing service and fix the permission issues, but your mileage may vary.

I would suggest to:

  • Set the port setting in the /etc/mongod.conf to be 27017 instead of 23654
  • The ownership of the files under directory /var/lib/mongodb and /var/log/mongodb should be owned by mongodb user, as per the settings in /etc/mongod.conf
  • Use the service starter to start the MongoDB process (systemctl), and avoid using sudo to run mongod manually
  • If the service failed to start, please post the error message in /var/log/mongodb/mongod.log. Since this file should be owned by the mongodb user, please be careful in extracting the content of this file as using sudo incorrectly could change the ownership of this file and put us back to the same permission issues again
  • If anyone else have sudo access to this machine, please let them know not to undo all your work that was done in the previous points by running sudo mongod or change any permission in any MongoDB-related directories

Best regards
Kevin

3 Likes