Reputation: 1164
I am trying to run a docker instance and keep coming across this server. Here is what I get after trying to setup the instance:
Starting instance ... done
Attaching to instance
instance | {"t":{"$date":"2020-12-08T14:06:42.033Z"},"s":"F", "c":"CONTROL", "id":20574, "ctx":"main","msg":"Error during global initialization","attr":{"error":{"code":38,"codeName":"FileNotOpen","errmsg":"Failed to open /var/log/mongodb/mongod.log"}}}
instance exited with code 1
The file permissions are:
$ ls -l /var/log/mongodb/mongod.log
-rwxr-xr-x 1 mongodb mongodb 0 Dec 8 19:32 /var/log/mongodb/mongod.log
What else I've tried:
mongodb
as owner and group to both the lib and log mongodb folders.I am not sure anymore where this issue is coming from. Would like to have some alternate solutions to this.
Upvotes: 6
Views: 15592
Reputation: 1582
I won't recommend using chmod 777
for fixing this issue. Rather change the ownership to MongoDB:
chown mongodb:mongodb /var/log/mongodb/mongod.log
Then you can start the MongoDB service:
$ sudo systemctl start mongod
$ sudo systemctl status mongod
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
Active: active (running) since Wed 2024-10-09 18:50:16 +06; 1s ago
Docs: https://docs.mongodb.org/manual
Main PID: 162606 (mongod)
Memory: 79.3M
CPU: 624ms
CGroup: /system.slice/mongod.service
└─162606 /usr/bin/mongod --config /etc/mongod.conf
Oct 09 18:50:16 pop-os systemd[1]: Started MongoDB Database Server.
Upvotes: 0
Reputation: 1496
I went thru a lot of posts, changed permissions, followed this one and tried it all:
Permission denied to read file owned by user
I even followed the tutorial at mongo step by step:
https://www.mongodb.com/docs/manual/tutorial/deploy-replica-set-with-keyfile-access-control/
And nothing worked for me.
This one:
sudo chown mongodb mongo.key
Didnt work either, but at the end, I thought of restarting the server, and after
sudo service mongod start
and it all worked.
I have no answer why this worked, but a restart on my three servers worked just perfect.
And here's my mongod.conf
security:
authorization: enabled
keyFile: /var/lib/mongodb/mongo.key
Thanks.
Upvotes: 1
Reputation: 469
If your mongodb was working well & suddenly it stopped working, then it can possible be an error related to permission. Below commands can be used to get back mongodb into running state -
sudo chmod 777 -R /var/log/mongodb // not good from safety perspective. sudo chmod 777 -R /var/lib/mongodb // not good from safety perspective. sudo rm -rf /tmp/mongod-*.sock
and them you can simply restart the server & check the status with below commands -
sudo service mongod restart sudo service mongod status or sudo systemctl restart mongod sudo systemctl status mongod
If this answer works for you, please vote it.
Upvotes: 2
Reputation: 47
I had the same issue. I think the permission could be wrong for the folder. Try setting the permission 777 for log and data
Upvotes: 3