Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-26575

Unable to start mongod service when omiting pidfilepath in mongod.conf

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.4.0-rc1
    • Affects Version/s: 3.2.10
    • Component/s: Packaging
    • Labels:
    • Fully Compatible
    • ALL
    • v3.2
    • Hide

      1. Populate a file named test.conf with yaml that does not contain a reference to pidfilepath:

      > cat test.conf
      storage:
          dbPath: /mnt/data/mongo3
          directoryPerDB: true
          engine: wiredTiger
          journal:
              enabled: true
      
      systemLog:
          logAppend: true
          quiet: false
          destination: syslog
      
      processManagement:
          fork: true
      
      security:
          keyFile: /etc/mongo.key
      
      replication:
          replSetName: testrepl
      
      setParameter:
          logUserIds: 1
      

      2. Set the config file

      > CONFIGFILE="test.conf"
      

      3. Parse the pidfilepath

      > PIDFILEPATH=`awk -F'[:=]' -v IGNORECASE=1 '/^[[:blank:]]*(processManagement\.)?pidfilepath[[:blank:]]*[:=][[:blank:]]*/{print $2}' "$CONFIGFILE" | tr -d "[:blank:]\"'" | awk -F'#' '{print $1}'`
      

      4. Run the check

      if [ -f $PIDFILEPATH ]; 
           then echo "Error starting mongod. $PIDFILEPATH exists." 
           RETVAL=1 
           return 
      fi
      

      5. Observe that the statement erroneously evaluates to true.

      Show
      1. Populate a file named test.conf with yaml that does not contain a reference to pidfilepath: > cat test.conf storage: dbPath: /mnt/data/mongo3 directoryPerDB: true engine: wiredTiger journal: enabled: true systemLog: logAppend: true quiet: false destination: syslog processManagement: fork: true security: keyFile: /etc/mongo.key replication: replSetName: testrepl setParameter: logUserIds: 1 2. Set the config file > CONFIGFILE= "test.conf" 3. Parse the pidfilepath > PIDFILEPATH=`awk -F '[:=]' -v IGNORECASE=1 '/^[[:blank:]]*(processManagement\.)?pidfilepath[[:blank:]]*[:=][[:blank:]]*/{print $2}' "$CONFIGFILE" | tr -d "[:blank:]\" '" | awk -F' # ' ' {print $1}'` 4. Run the check if [ -f $PIDFILEPATH ]; then echo "Error starting mongod. $PIDFILEPATH exists." RETVAL=1 return fi 5. Observe that the statement erroneously evaluates to true.
    • Build 2016-10-31

      File: init.d-mongod

      The problem occurs when the contents of the $CONFIGFILE does not contain a reference to pidfilepath. In this case, the parsing results in a null string value for PIDFILEPATH. The if-statement that uses PIDFILEPATH does not quote the variable and so the if-statement will evaluate to true even though there is obviously no such 'null' file.

      This was observed when running

      service mongod start
      

      resulting in the error

      Error starting mongod.  exists.
      

      Surrounding the PIDFILEPATH in quotes should fix the problem:

      if [ -f "$PIDFILEPATH" ];
      then echo "Error starting mongod. $PIDFILEPATH exists."
      RETVAL=1
      return
      fi

      The documentation states that the pidfilepath is not required: "Without a specified processManagement.pidFilePath option, the process creates no PID file."

      Appears to be resulting from the changes made in SERVER-12048

            Assignee:
            brian.samek@mongodb.com Brian Samek
            Reporter:
            hpatel001 Harsh Patel
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: