[SERVER-26575] Unable to start mongod service when omiting pidfilepath in mongod.conf Created: 11/Oct/16  Updated: 04/Jan/17  Resolved: 13/Oct/16

Status: Closed
Project: Core Server
Component/s: Packaging
Affects Version/s: 3.2.10
Fix Version/s: 3.4.0-rc1

Type: Bug Priority: Major - P3
Reporter: Harsh Patel Assignee: Brian Samek
Resolution: Done Votes: 0
Labels: bkp
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Related
related to SERVER-12048 Calling "service mongod start" with m... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v3.2
Steps To Reproduce:

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.

Sprint: Build 2016-10-31
Participants:

 Description   

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



 Comments   
Comment by Ramon Fernandez Marina [ 14/Oct/16 ]

Thanks for the detailed bug report hpatel001. A fix has been committed to the master branch, and will be part of the upcoming 3.4.0-rc1 release candidate.

The fix is a change in the init script, so if this bug is an issue for you it's easy to apply the fix to your existing installation.

Regards,
Ramón.

Comment by Githook User [ 13/Oct/16 ]

Author:

{u'username': u'bsamek', u'name': u'Brian Samek', u'email': u'brian.samek@mongodb.com'}

Message: SERVER-26575 Quote PIDFILEPATH
Branch: master
https://github.com/mongodb/mongo/commit/1fcd8435b8c52fa4284be51d8c44a273f0db5382

Generated at Thu Feb 08 04:12:33 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.