Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

mongod --fork stops with child process failed, exited with error number 1

ErrorERROR: child process failed, exited with error number 1

Short answer

mongod --fork starts a child that detaches, and the parent only reports that the child died. The real reason is in the log file, so give --fork a log with --logpath and read it. Typical causes: no log destination was given, or the data files belong to another storage engine.

  • Applies to MongoDB 8.0, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Run mongod with a log file and read it. The log has the real error that the parent process hides.

    sudo mongod --dbpath /var/lib/mongodb --logpath /var/log/mongodb/mongod.log --fork
    sudo tail -n 30 /var/log/mongodb/mongod.log
  2. 2Match what you see, then jump to its fix

    1. 1The command had --fork but no --logpath or --syslog--fork was used without a log destinationFix
    2. 2mongod exits right after start on a data directory made with a different storage engineThe data files do not match the storage engineFix
    3. 3mongod fails only when started by the service after you edited systemLog.path or forkThe package init script and the config disagreeFix

What does the error look like?

  • ERROR: child process failed, exited with error number 1

Cause 1 of 3

--fork was used without a log destination

1Check

To use --fork you must configure log output with --logpath or --syslog.

ps aux | grep [m]ongod; grep -n "fork\|logpath\|systemLog" /etc/mongod.conf

2Fix

Add --logpath on the command line, or set systemLog.destination to file and systemLog.path in the config file.

mongod --config /etc/mongod.conf --fork
# /etc/mongod.conf
systemLog:
  destination: file
  path: /var/log/mongodb/mongod.log

3Verify

mongod starts and prints the child's process ID.

pgrep -a mongod

Confirmed by mongodb.com

Did this fix it?

Cause 2 of 3

The data files do not match the storage engine

1Check

The files in --dbpath must correspond to the storage engine in --storageEngine. If they do not, mongod does not start.

grep -n "storageEngine" /etc/mongod.conf

2Fix

Use the engine the data was created with, or point --dbpath at an empty directory for a new database.

sudo mkdir -p /var/lib/mongodb-new
mongod --dbpath /var/lib/mongodb-new --logpath /var/log/mongodb/mongod.log --fork

3Verify

mongod keeps running after the command returns.

pgrep -a mongod

Confirmed by mongodb.com

Did this fix it?

Cause 3 of 3

The package init script and the config disagree

1Check

The Linux package init scripts depend on specific values for systemLog.path, storage.dbPath and processManagement.fork. Changing them may stop mongod from starting.

grep -n "path\|dbPath\|fork" /etc/mongod.conf

2Fix

Restore the defaults of the packaged config, or run mongod yourself with your own init script. With systemd you do not need fork at all.

sudo systemctl start mongod

3Verify

The service shows active.

systemctl status mongod --no-pager

Confirmed by mongodb.com

Did this fix it?

How do I stop it coming back?

  • Prefer systemd to --fork on modern Linux; the docs name a controlling process such as systemd as the other way to daemonize.
  • Always give --fork a log destination, and read the log after the first start.
  • Keep dbPath and storage engine settings in one config file under version control.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.