[Fixed] Mongodb error: Environment variable MONGODB_CONFIG_OVERRIDE_NOFORK == 1 – Mongodb

by
Ali Hasan
centos7 mongodb

Quick Fix: Put these lines in the file:

[Service]
User=mongod
Group=mongod
Environment="OPTIONS=-f /etc/mongod.conf"
EnvironmentFile=-/etc/sysconfig/mongod
ExecStart=/usr/bin/mongod $OPTIONS
ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb
ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb
ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb
ExecStartPre=/usr/bin/mkdir -p /var/lib/mongo
ExecStartPre=/usr/bin/chown mongod:mongod /var/lib/mongo
ExecStartPre=/usr/bin/chmod 0700 /var/lib/mongo
PermissionsStartOnly=true
PIDFile=/var/run/mongodb/mongod.pid
Type=forking 

The Problem:

A MongoDB instance on CentOS 7 is unable to restart due to the error "Environment variable MONGODB_CONFIG_OVERRIDE_NOFORK == 1, overriding "processManagement.fork" to false." This error occurs when the MONGODB_CONFIG_OVERRIDE_NOFORK environment variable is set to 1, which disables forking and can disrupt the normal operation of MongoDB. The server previously worked without issue, but the root cause of the error remains unclear.

The Solutions:

Solution 1: {title}

To resolve the error “Environment variable MONGODB_CONFIG_OVERRIDE_NOFORK == 1,” follow these steps:

  1. Check the service file:

    Run systemctl cat mongod to check if the following lines are present in the service file:

    ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb
    ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb
    ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb
    

    These lines create a directory in /var/run/mongodb with appropriate permissions, allowing MongoDB to access it.

  2. Modify the service file (newer version):

    If the previous lines are not present, add them to the service file, and use the following syntax:

    ExecStartPre+=/usr/bin/mkdir -p /var/run/mongodb
    ExecStartPre+=/usr/bin/chown mongod:mongod /var/run/mongodb
    ExecStartPre+=/usr/bin/chmod 0755 /var/run/mongodb
    
  3. Create a service file copy (recommended):

    Instead of editing the default service file directly, create a copy in /etc/systemd/system/mongod.service. Place your customized settings there. This ensures that your changes will not be overwritten during MongoDB updates.

  4. Restart the MongoDB service:

    Run systemctl restart mongod to apply the changes and restart the service.

These steps should resolve the “Environment variable MONGODB_CONFIG_OVERRIDE_NOFORK == 1” error and allow MongoDB to start successfully.

Q&A

Error when I try to restart mongo in centos web panel

Environment variable MONGOD_CONFIG_OVERRIDE_NOFORK == 1, overriding "processManagement.fork" to false