51

In attempting to run the command

mongod --fork --logpath /var/log/mongodb.log

On a amazon ec2 32 bit instance (Amazon Linux AMI release 2014.09), I run into the following error:

2015-02-18T18:14:09.007+0000 
2015-02-18T18:14:09.007+0000 warning: 32-bit servers don't have journaling    
enabled by default. Please use --journal if you want durability.
2015-02-18T18:14:09.007+0000 
about to fork child process, waiting until server is ready for connections.
forked process: 17116
ERROR: child process failed, exited with error number 1

I also notice no log file is created in the process.

Ryder Bergerud
  • 753
  • 1
  • 6
  • 15
  • 3
    does `/data/db` exist? errno 1: `#define EPERM 1 /* Operation not permitted */`. That would also explain why no log file is created - the user isn't allowed to. – mnemosyn Feb 18 '15 at 18:28
  • It does, I have a number of database files I've been working with in there too. – Ryder Bergerud Feb 18 '15 at 19:05
  • `@mnemosyn ls -al total 245772 drwxr-xr-x 2 ec2-user root 4096 Feb 5 17:14 . drwxr-xr-x 3 root root 4096 Feb 4 17:40 .. -rw------- 1 ec2-user ec2-user 67108864 Feb 5 21:42 brands.0 -rw------- 1 ec2-user ec2-user 16777216 Feb 5 21:42 brands.ns -rw------- 1 ec2-user ec2-user 67108864 Feb 4 22:54 brandsTest2.0 -rw------- 1 ec2-user ec2-user 16777216 Feb 4 22:54 brandsTest2.ns -rw------- 1 ec2-user ec2-user 67108864 Feb 18 17:52 local.0 -rw------- 1 ec2-user ec2-user 16777216 Feb 18 17:52 local.ns -rwxrwxr-x 1 ec2-user ec2-user 0 Feb 18 17:59 mongod.lock` – Ryder Bergerud Feb 18 '15 at 19:07
  • Hm, then my guess appears to be wrong. I'd still investigate the errno 1 route... – mnemosyn Feb 18 '15 at 19:08
  • @mnemosyn where did you find the error codes? I was looking at [https://github.com/mongodb/mongo/blob/master/docs/errors.md](https://github.com/mongodb/mongo/blob/master/docs/errors.md) and couldn't see it. – Ryder Bergerud Feb 18 '15 at 19:12
  • These are linux error codes. I googled it, e.g. http://www.virtsync.com/c-error-codes-include-errno – mnemosyn Feb 18 '15 at 19:15
  • Have you tried running the command without `--fork`? Does it produce an error message? If so, what? If not, what does it say in the log, if it creates one? – wdberkeley Feb 19 '15 at 01:00
  • Running mongod works fine on its own. With the logpath specified I get `]$ mongod --logpath /var/log/mongod.log 2015-02-19T01:34:12.656+0000 2015-02-19T01:34:12.656+0000 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability. 2015-02-19T01:34:12.656+0000 2015-02-19T01:34:12.657+0000 SEVERE: Failed global initialization: FileNotOpen Failed to open "/var/log/mongod.log"` – Ryder Bergerud Feb 19 '15 at 01:36

12 Answers12

84

I had the same thing and it turned out to be a permissions issue. If the owner of the child process cannot access the log path or the log path does not exist, it will fail.

What I did was put the log directory in my home directory:

mkdir ~/log
mongod --fork --logpath ~/log/mongodb.log

If you really want to put it in your /var/log directory, just change the permissions.

onetwopunch
  • 3,279
  • 2
  • 29
  • 44
  • 1
    For those wondering, I had to change the permissions on */var/log* to 777 – kabadisha Feb 07 '17 at 10:54
  • 3
    @kabadisha you really shouldn't have 777 on /var/log there's lots of potentially sensitive data stored in that directory. Try changing the directory perms to 740 and create the log file first. Find the user mongod is running as and chown that file. Then chmod the file with 744. I'm just guessing here, but just about any perms are better than 777 on /var/log good luck – onetwopunch Feb 07 '17 at 14:36
  • It is a good point. I had to chown the /var/log dir to my user and then give 740 permissions. – kabadisha Feb 08 '17 at 17:21
  • That's fascinating. I was throwing my head to the walls. Thanks! – Yusuf Kamil AK Dec 06 '17 at 22:01
  • How can I do this running mongod from a docker-compose file? @onetwopunch – Ekaitz Hernandez Troyas Oct 25 '19 at 23:14
  • @EkaitzHernandezTroyas did you figure out a solution for this? I have a similar problem: Here's what my Docker-compose looks like: ` rs101: image: percona/percona-server-mongodb container_name: rs101 hostname: rs101 networks: - backend command: "--port=27017 --replSet rs --auditDestination=file --auditFormat=JSON --auditPath=/var/log/tokumx/audit_101.json" volumes: - mongo_db_101:/data/db - ./mongo-audit-logs/rs101:/var/log/tokumx ` – Ahmad Salman Khan Aug 28 '23 at 09:31
12

I also had the same error, however I used sudo it and ran sudo mongod --fork --logpath /var/log/mongodb.log. As @jryancanty mentioned, it's simply a permissions error.

Nathan L.
  • 243
  • 2
  • 10
8

For anyone else running into this error [even if you run it with sudo] make sure that you state the filename of the log file as in: /var/log/mongodb.log. I had just the directory path as in /var/log/ since I miss read the mongo docs.

parsethis
  • 7,998
  • 3
  • 29
  • 31
4

I have same issue after

sudo rm /tmp/mongodb-27017.sock
sudo chown mongod:mongod /var/log/mongodb

and all worked.

Savorboard
  • 41
  • 2
  • This fixed it for me. Simply changing permissions on the directory changed my error message from 1 to 100. I needed to make the mongod user the owner of the directory and it worked. – mhodges Feb 04 '21 at 19:18
  • This worked for me too as I was having error in spite of setting correct permissions. – Anik Chakrabortty Jul 05 '21 at 08:57
3

I have deleted old

/var/run/mongodb/mongod.pid

and all worked.

rlib
  • 7,444
  • 3
  • 32
  • 40
  • Mine won't run because this file is missing :(. Says `Cannot write pid file to /var/run/mongodb/mongod.pid: No such file or directory` – Katie Jul 21 '17 at 23:57
1

If you have a keyfile, it is also possible that the permissions are too open. Make sure you set it to 0400

masterforker
  • 2,443
  • 2
  • 25
  • 39
1

I incorrectly set the log path to var/mongodb/db/mongo.log instead of /var/mongodb/db/mongo.log so Mongo was trying to access a non-existent folder in /home.

Patience Mpofu
  • 433
  • 4
  • 9
0

this might work if you see issues with /tmp/mongodb-27017.sock in the log file

sudo chown mongodb:mongodb /tmp/mongodb-27017.sock

kgs
  • 1,654
  • 2
  • 18
  • 19
  • I was trying to intital Sync and in my case the error was : keyFile was owned by root, once I changed it to mongo - it started working -- hope it helps someone – Immu Aug 31 '23 at 11:00
0

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

In ubuntu no need to change permissions in /var, use full logfile name in logpath

zKaj
  • 9
  • 4
0

I got the same issues because of user permission , when i logged in ubuntu with user who's don't have permission to create file then also this error was occur.

So , you have to run the command with sudo. :)

Raman Kumar
  • 131
  • 8
0

I have same issue after remove mongo from EPEL repo (2.x) and install mongo from mongo repo (4.x).

journalctl -xe says:

ERROR: child process failed, exited with error number 1

In my case I have old log file with root permissions. Just set correct permission or delete log and check log directory permission.

Alexander
  • 11
  • 2
0

This error is also generated if you are already having folder for dbpath where db data is being stored and in conf file you gave a new path for dbpath. When you are creating new folders for dbpath, logs and PID then delete the old ones, if they are there.

Raghav Gupta
  • 341
  • 1
  • 6
  • 20