9 / 9
Jul 2021

Whenever I restart my system MongoDB server fails to start.

Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Sat 2021-07-03 14:24:44 IST; 15min ago Docs: https://docs.mongodb.org/manual Process: 14963 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=1/FAILURE) Main PID: 14963 (code=exited, status=1/FAILURE)

The only solution for this is to run

sudo mongod --fork --logpath /var/lib/mongodb/mongodb.log --dbpath /var/lib/mongodb

after the system restart.

But it gets annoying to start MongoDB every time on system restart.
Is there any other solution to this problem?

Yes there is a file /usr/bin/mongod

and content of configuration file

# mongod.conf # for documentation of all options, see: # http://docs.mongodb.org/manual/reference/configuration-options/ # Where and how to store data. storage: dbPath: /var/lib/mongodb journal: enabled: true # engine: # mmapv1: # wiredTiger: # where to write logging data. systemLog: destination: file logAppend: true path: /var/log/mongodb/mongod.log # network interfaces net: port: 27017 bindIp: 127.0.0.1 # how the process runs processManagement: timeZoneInfo: /usr/share/zoneinfo #security: #operationProfiling: #replication: #sharding: ## Enterprise-Only Options: #auditLog: #snmp:

also mongod.service

[Unit] Description=MongoDB Database Server Documentation=https://docs.mongodb.org/manual After=network-online.target Wants=network-online.target [Service] User=mongodb Group=mongodb EnvironmentFile=-/etc/default/mongod ExecStart=/usr/bin/mongod --config /etc/mongod.conf PIDFile=/var/run/mongodb/mongod.pid # file size LimitFSIZE=infinity # cpu time LimitCPU=infinity # virtual memory size LimitAS=infinity # open files LimitNOFILE=64000 # processes/threads LimitNPROC=64000 # locked memory LimitMEMLOCK=infinity # total threads (user+kernel) TasksMax=infinity TasksAccounting=false # Recommended limits for mongod as specified in # https://docs.mongodb.com/manual/reference/ulimit/#recommended-ulimit-settings [Install] WantedBy=multi-user.target

In your config file you have

but you use a different one on the command line

May be one exists but not the other.

Ok, corrected the log path to path: /var/lib/mongodb/mongodb.log in the configuration file, but the server still failed after a restart

Most likely it fails because you started mongod with sudo. By doing so the files and directories are now own by root while the service file tries to start with user mongodb.

Ok, changed the ownership of the /var/lib/mongodb, and everything works.

One question, I installed MongoDB server following the documentation for installation in ubuntu and never edited configuration files or others. So does it mean there is something wrong in the installation guide?

No there is nothing wrong with the installation guide. You must have missed the part where it says that you must create the directories.

By the way the correct path for the log is the one you had originally in the configuration file. The one you used on the command line was wrong. It works with the log in /var/lib but logs usually resides in /var/log.

Closed on Jul 8, 2021

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