MongoDB didn't start because of File permission issue

MongoDB didn't start because of File permission issue

# mongodb# linux# database# webdev
MongoDB didn't start because of File permission issueRuben Alvarado

The Wired Tiger Turtle in the logs Originalled published on Web Warrior Toolbox A...

The Wired Tiger Turtle in the logs


Originalled published on Web Warrior Toolbox

A Wired Tiger Turtle Story...

While troubleshooting a project, I wanted to run the db locally before deploying my hotfix. I set my pc for that and I mocked a database with some useful data for my test before deploying to production that day.

Two days later a new issue that needed a hotfix came to me and I needed to test again with a local database. I tried to start the db with the usual command systemctl start mongod but I saw it didn't start when I checked with systemctl status mongod.

When I checked status I saw a message saying that it didn't start but i couldn't understand the reason why.๐Ÿคจ

After following multiple suggestions from chatbots and getting lost myself ๐Ÿ˜ตโ€๐Ÿ’ซ I understood that the answer to that question was in a place I didn't use to look at ๐Ÿ’ฌโ€‹: THE LOGS! ๐Ÿชตโ€‹

In Linux you have that place dedicated to record what did your applications say and probably you didn't see or don't remember. Just look at /var/log and then check your respective log.

In my case I found the file /var/log/mongodb/mongod.log

Since it had many lines I just checked the last part of the log with the tail command:

sudo tail -n300 /var/log/mongodb/mongod.log
Enter fullscreen mode Exit fullscreen mode

Still with that I got a wall of text so i decided to fed my chatbot to provide some advice. The chatbot showed that the most frequent text was indeed the most important part of this issue.

[ERROR]: __posix_open_file, 924: /var/lib/mongodb/WiredTiger.turtle: handle-open: open: Permission denied"}} 
Enter fullscreen mode Exit fullscreen mode

A wild Wire-tiger-turtle-appeared!๐Ÿ”Œโ€‹๐Ÿฏโ€‹โ€‹๐Ÿข

The chatbot suggested that /var/lib/mongodb/WiredTiger.turtle should be owned by mongodb. I noted the file was owned by root. I tryed changing the owner to mongodb and it didn't work. Then tried changing the folder to be owned by mongodb. This last attemp was sucesful when i restarted mongod and check with systemctl status mongod.

What I learned from that story

This story is longer than what I wrote. At the start I didn't know where to look and i received suggestions from the chatbot that lead me nowhere. This is the reason why I want to highlight the importance of logs. They provide some important detail that you can use to feed a chatbot, chat with another team member and to understand yourself what is happening. Take this story as a way to keep checking them when issues arise.

Side story

why did that wiredTiger.turtle file became owned by root? Well it happened that when I did the first hot fix I started the db with sudo mongod --config /etc/mongod.conf

With that command I could use mongodb without problems during that session but I got the problem I tried to tweak again the app two days later.

Let's keep coding, dev-san โ€‹๐Ÿค“โ€‹ ้ ‘ๅผตใฃใฆ!