When starting MongoDB with a command like mongod --dbpath=/data/club --port=27017 --fork --logpath=/var/log/mongodb/mongodb.log, you may encounter the following error:
about to fork child process, waiting until server is ready for connections.
forked process: 43110
all output going to: /var/log/mongodb/mongodb.log
log file [/var/log/mongodb/mongodb.log] exists and couldn't make backup [/var/log/mongodb/mongodb.log.2014-11-17T06-55-20]; run with --logappend or manually remove file: errno:13 Permission denied
Bad logpath value: "/var/log/mongodb/mongodb.log"; terminating.
ERROR: child process failed, exited with error number 1
This error typically indicates that the MongoDB service was not shut down properly, possibly due to a system crash, leaving a lock file or causing permission issues with log files.
To resolve this issue, follow these steps:
-
Remove Lock and Log Files: Delete the
mongod.lockfile and any old log files, such asmongodb.log.2014-11-17T06-55-20. Ensure you have the necessary permissions. You may need to clear the entire log directory. -
Attempt Database Repair: Run the repair command. Note that with journaling enabled, the
--repairpathmust be a subdirectory of--dbpath.mongod --repair --dbpath /data/db/ --repairpath /data/db/repair_tempIf you encounter an error stating the repair path must be a subdirectory, adjust the command accordingly. An incorrect path may lead to an assertion failure during shutdown.
-
Restart MongoDB: After cleaning up files and repairing the database, restart the service.
mongod --dbpath=/data/db --port=27017 --fork --logpath=/var/log/mongodb/mongodb.logA successful startup will produce output similar to:
about to fork child process, waiting until server is ready for connections.
forked process: 43144 all output going to: /var/log/mongodb/mongodb.log log file [/var/log/mongodb/mongodb.log] exists; copied to temporary file [/var/log/mongodb/mongodb.log.2014-11-17T07-21-41] child process started successfully, parent exiting ```