mongod --fork stops with child process failed, exited with error number 1
ERROR: child process failed, exited with error number 1Short 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.
Fix it fast
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.log2Match what you see, then jump to its fix
- 1
The command had --fork but no --logpath or --syslog--fork was used without a log destinationFix - 2
mongod exits right after start on a data directory made with a different storage engineThe data files do not match the storage engineFix - 3
mongod fails only when started by the service after you edited systemLog.path or forkThe package init script and the config disagreeFix
- 1
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.conf2Fix
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.log3Verify
mongod starts and prints the child's process ID.
pgrep -a mongodConfirmed by mongodb.com
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.conf2Fix
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 --fork3Verify
mongod keeps running after the command returns.
pgrep -a mongodConfirmed by mongodb.com
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.conf2Fix
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 mongod3Verify
The service shows active.
systemctl status mongod --no-pagerConfirmed by mongodb.com
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
Servers
mongod.service exits with an error on Ubuntu and the cause is hidden
Attempted to create lock file on a read-only directory: ...
When mongod.service exits straight away, the reason is in the mongod log, not in systemctl.
2 causes, each with a fixDatabases
Installing the Airflow MySQL provider fails on pkg-config or mysqlclient
Building the mysqlclient wheel fails during the install
The Airflow MySQL provider depends on mysqlclient, which pip compiles against the MySQL C client library.
2 causes, each with a fixDatabases
Compiling a C or C++ program that includes mysql.h fails
undefined reference to `mysql_init'
The compiler only finds mysql.h when the MySQL client development files are installed and their folder is on the include path.
3 causes, each with a fixDatabases
DBeaver cannot run pg_restore: the utility is not found in the client home
Utility 'pg_restore' not found in client home '/usr/lib' (/usr/lib)
DBeaver runs pg_restore from a local PostgreSQL client folder; it does not bundle one.
3 causes, each with a fixDatabases
Django cannot connect to PostgreSQL: connection refused on port 5432, locally or in Docker
Is the server running on that host and accepting TCP/IP connections?
Connection refused means nothing accepted the connection at the host and port Django used.
4 causes, each with a fixDatabases
manage.py test stops with 'permission denied to create database' on PostgreSQL
django.db.utils.ProgrammingError: permission denied to create database
Django creates a separate database called test_ plus your database name, using the DATABASES USER.
2 causes, each with a fix