Mongod --fork --logpath /var/log/mongodb.log gives error = ERROR: child process failed, exited with 1

[centos@ip-172-26-2-104 ~]$ pwd

[centos@ip-172-26-2-104 ~]$ ls -l
drwxrwxrwx. 3 centos centos 26 Jul 1 09:05 mongodb

[centos@ip-172-26-2-104 ~]$ ls -l mongodb/log
-rwxrwxrwx. 1 centos centos 0 Jul 1 09:01 a

so i have both the data and log directories with 777 permission

[centos@ip-172-26-2-104 ~]$ ps -ef | grep mongod
centos 15164 14007 0 09:32 pts/5 00:00:00 grep --color=auto mongod

[centos@ip-172-26-2-104 ~]$ mongod --dbpath mongodb --port 27017 --logpath mongodb/log --fork --logappend --bind_ip_all

about to fork child process, waiting until server is ready for connections.
forked process: 15194
ERROR: child process failed, exited with 1
To see additional information in this output, start without the “–fork” option.

[centos@ip-172-26-2-104 ~]$ mongod --dbpath mongodb --port 27017 --logpath mongodb/log --logappend --bind_ip_all

{“t”:{"$date":“2022-07-01T09:33:45.030Z”},“s”:“F”, “c”:“CONTROL”, “id”:20574, “ctx”:"-",“msg”:“Error during global initialization”,“attr”:{“error”:{“code”:38,“codeName”:“FileNotOpen”,“errmsg”:“logpath “/home/centos/mongodb/log” should name a file, not a directory.”}}}
[centos@ip-172-26-2-104 ~]$

There is nothing we can add to the error message you got.

Specify a file for --logpath rather than a directory.

I got the fix,

sudo chown -R mongod:mongod

Mongod fork issue needs mongod user permission

there has to be directory only, i confirmed over testing

Only when you start it as mongod user. But you don’t. Your shell prompt and current working directory seems to indicate that you are user centos.

What do you mean by the above?

logpath has to be file. if you redo your ls command you will notice a new file named mongdblog. You have a directory mongolog but it is not being used.

Next time you publish terminal output, please do it using Markdown text so that we can cut-n-paste part of it in our answers.