Mongod: Failed global initialization

  1. I am facing trouble with fork
vagrant@m103:~$ tree
.
|-- data
|   |-- db
|   `-- logs
|-- mongod.conf
`-- var
    `-- mongodb
        |-- db
        `-- logs
7 directories, 1 file
vagrant@m103:~$ mongod -f mongod.conf
about to fork child process, waiting until server is ready for connections.
forked process: 15554
ERROR: child process failed, exited with error number 1
To see additional information in this output, start without the "--fork" option.
  1. Without fork

     vagrant@m103:~$ ls
     data  mongod.conf  var
     vagrant@m103:~$ cat mongod.conf
     storage:
       dbPath: "/var/mongodb/db/"
     systemLog:
       path: "/var/mongodb/logs/mongod.log"
       destination: "file"
     net:
       bindIp : "127.0.0.1,192.168.103.100"
       port: 27000
     security:
       authorization: enabled
     # processManagement:
     #   fork : true
    
     vagrant@m103:~$ mongod -f mongod.conf
     2019-10-18T08:59:55.719+0000 F CONTROL  [main] Failed global initialization: FileNotOpen: Failed to open "/var/mongodb/logs/mongod.log"

Hi @Rakshith_79674,

The error indicates that either you haven’t created the directory “/var/mongodb/logs” or you haven’t provided the appropriate permissions to it.

Please share the output of below command:

ls -lrt /var/mongodb/logs

If the directory exists, please grant the appropriate permissions to it as mentioned in the lecture notes as well.

Thanks,
Muskan
Curriculum Support Engineer

1 Like

logs directory is empty

vagrant@m103:/var$ ls
backups cache chef crash lib local lock log m103 mail opt run spool tmp

or

vagrant@m103:~$ tree
.
|-- data
| |-- db
| -- logs |-- mongod.conf – var
-- mongodb |-- db – logs

Hi @Rakshith_79674,

We first need to find if vagrant has permissions to open the file and write logs into it or not.

To do so, we are running the “ls -l” command.

Please run ls -lrt /var/mongodb/logs at the prompt vagrant@m103 and share the output.

Thanks,
Muskan
Curriculum Support Engineer

1 Like

I am confused about the permission and log path

I have two var directories

  1. / root level var directory

vagrant@m103:/var$ ls -1
backups
cache
chef
crash
lib
local
lock
log
m103
mail
opt
run
spool
tmp

Here, I don’t find mongodb directory inside var

  1. ~ home level var directory

vagrant@m103:~/var$ ls
mongodb
vagrant@m103:~/var$ cd mongodb/
vagrant@m103:~/var/mongodb$ ls
db logs

There are no files under both logs and db directory.

Sorry to bother you so much today as I am new to Linux cmd please help me. :neutral_face:

Run exactly what @Muskan_47318 gave you.

1 Like

ls: cannot access /var/mongodb/logs: No such file or directory

I get this

Hi @Rakshith_79674,

Yes, this is the the var directory that we are referring to.

Here, you have shared the output of “ls” command which will list down all the files and sub-directories in the current directory.
What we need to check is the permissions on the directory. These permissions determine if you will able to create/write to a file in this directory or not.

"ls -lrt" will help you see the permissions as well. Please refer to the screenshot below - this is an example of what we require.

vagrant@m103:~$ ls

1 data

vagrant@m103:~$ ls -lrt

total 8

drwxrwxrwx 2 vagrant vagrant 4096 Sep 2 12:30 data

-rw-rw-r-- 1 vagrant vagrant 320 Sep 5 13:54 1

Also, do not “cd” into var when you run this command, please run it as below:

vagrant@m103:~$ ls -lrt /var/mongodb/logs

For basic linux commands, please refer to the following links, they might be helpful:


https://www.thegeekstuff.com/2009/03/8-essential-vim-editor-navigation-fundamentals/
https://www.tecmint.com/linux-directory-structure-and-important-files-paths-explained/

Thanks,
Muskan
Curriculum Support Engineer

1 Like

vagrant@m103:~$ ls -lrt
total 12
drwxrwxr-x 3 vagrant vagrant 4096 Oct 18 08:17 var
drwxrwxrwx 4 vagrant vagrant 4096 Oct 18 08:52 data
-rwxrwxr-x 1 vagrant vagrant 249 Oct 18 09:23 mongod.conf

Great! @Rakshith_79674 - Now as you can see we have the “var” directory here with all the required permissions and correct owner too.

drwxrwxr-x 3 vagrant vagrant 4096 Oct 18 08:17 var

But since our log files are created inside /var/mongodb/logs directory, we need to check for that specifically.

So, please run the below command:

vagrant@m103:~$ ls -lrt /var/mongodb/logs

Thanks,
Muskan
Curriculum Support Engineer

1 Like

You might have missed the post where @Rakshith_79674 ran this confirming that the sub dir doesn’t exist… few posts up :slightly_smiling_face:

1 Like

drwxrwxr-x 4 vagrant vagrant 4096 Oct 18 08:25 mongodb
drwxrwxr-x 2 vagrant vagrant 4096 Oct 18 08:17 db
drwxrwxr-x 2 vagrant vagrant 4096 Oct 18 10:18 logs

vagrant:vagrant is the owner and group respective permission for all the dir and sub dir.
Am I making any mistakes?

root level var looks like this

drwxr-xr-x 14 root root 4096 Oct 18 03:11 var

@Rakshith_79674, when you do

look at your prompt. What you do is in fact ls -lrt /home/vagrant/. When you did ls -lrt /var/mongodb/logs and you got

It means that the file or directory does not exist. In this case your config file wants it to be a directory. You must create it and give it the appropriate ownership and permissions. The command mkdir is used to create directories, chown allows you to change ownership and chmod changes the permissions. And note that /var is not the same as var (most of the time). The leading slash is important just like c:\ in Windows.

1 Like

Please look at this,
Should I change the permission of /home/vagrant directory like this :point_right: drwxrwxrwx
If I am going wrong please guide me :neutral_face:

vagrant@m103:~ ls data mongod.conf vagrant@m103:~ mkdir /mongodb
mkdir: cannot create directory ‘/mongodb’: Permission denied
vagrant@m103:~ cd .. vagrant@m103:/home ls
ubuntu vagrant
vagrant@m103:/home$ ls -lrt
total 8
drwxr-xr-x 3 ubuntu ubuntu 4096 Oct 18 03:07 ubuntu
drwxr-xr-x 5 vagrant vagrant 4096 Oct 18 17:48 vagrant
vagrant@m103:/home$

$home

drwxr-xr-x 4 root root 4096 Oct 18 03:07 home

under home

drwxr-xr-x 3 ubuntu ubuntu 4096 Oct 18 03:07 ubuntu
drwxr-xr-x 6 vagrant vagrant 4096 Oct 18 18:04 vagrant

under vagrant

-rwxrwxr-x 1 vagrant vagrant 246 Oct 18 17:18 mongod.conf
drwxrwxr-x 2 vagrant vagrant 4096 Oct 18 17:58 mongodb
drwxrwxrwx 4 vagrant vagrant 4096 Oct 18 18:07 data
vagrant@m103:~$ ls mongod
ls: cannot access mongod: No such file or directory

Here, dwrxwrxr-x on mongodb d stands for directory right, then why does it says

ls: cannot access mongod: No such file or directory

To create your directory, try this:
mkdir -p /var/mongodb/logs

The first backslash is important so remember to include it in your config file.

1 Like

It’s permission denied
how to provide permission?

vagrant@m103:~$ ls
data mongod.conf

vagrant@m103:~$ mkdir -p /var/mongodb/logs
mkdir: cannot create directory ‘/var/mongodb’: Permission denied

:point_up_2: This wasn’t working so I tried the code below :point_down:

I tried creating

mkdir var

and changed mod

chmod -R 777 var

Ok, suggest you create it somewhere else:
mkdir -p /data/mongodb/logs

Fyi, you can use sudo mkdir <path> to create the directory and again use sudo chmod to change the permissions. But, it’s better you leave /var as-is and create it somewhere else.

1 Like

vagrant@m103:~$ sudo mkdir -p /var/mongodb/logs

vagrant@m103:~$ ls
data mongod.conf

vagrant@m103:~$ sudo chmod -R 777 /var/mongodb/logs

vagrant@m103:~$ ls
data mongod.conf

This is not reflecting when i list.
cmd executed successfully

Like we’ve mentioned multiple times, ls /var/ and ls are different locations.

Look in ls /var/
Don’t look in ls

1 Like

vagrant@m103:~$ mongod -f mongod.conf
about to fork child process, waiting until server is ready for connections.
forked process: 19082
child process started successfully, parent exiting

/any-file-name means it is root level
without / it means home dir
am i right?