简体   繁体   中英

“dirname: missing operand” error while starting mongod service

I recently installed mongo 2.6.5 version on our Red Hat enterprise Linux server. Everything was working fine, until I decided to make a change in /etc/mongod.conf file. I noticed that from version 2.6 above mongo supports conf file in YAML fomat. (the reason I wanted to make a change was, I wanted to enable the authentication on mongo instance)

http://docs.mongodb.org/manual/reference/configuration-options/

I changed my config file which used to look like below (I am adding only a portion of the config):

# mongod.conf

#where to log
logpath=/var/log/mongodb/mongod.log

logappend=true

# fork and run in background
fork=true

#port=27017

dbpath=/var/lib/mongo

# location of pidfile
pidfilepath=/var/run/mongodb/mongod.pid

My changed file mongod.conf file looks like below now:

systemLog:
    destination: file
    path: "/var/log/mongodb/mongodb.log"
    logAppend: true

storage:
    dbPath: "/var/lib/mongo"
    journal:
        enabled: true

processManagement:
    pidFilePath: "/var/run/mongodb/mongod.pid"
    fork: true

security:
    authorization: true![enter image description here][1]

Now when I try to run the mongod service it is giving me error (see attached picture): dirname: missing operand Try 'dirname --help' for more information Starting mongod: [FAILED]

When I revert my mongod.conf file to previous version, then the service runs fine. Do I need to change something in my mongo installation to make it use YAML format of config?

A few things:

  1. make sure that you define a PID file location in /etc/mongod.conf

     pidfilepath=/var/run/mongodb/mongod.pid 
  2. change the "daemon" line in /etc/init.d/mongod to explicitly use the PID file

     daemon --user "$MONGO_USER" --check "$mongod" --pidfile "$PIDFILE" "$NUMACTL $mongod $OPTIONS >/dev/null 2>&1" 

In addition, ensure that the following are all owned by mongod

  • /var/log/mongodb
  • /var/run/mongodb
  • your dbpath

虽然mongod支持YAML配置文件,但似乎没有修改initscripts来处理它们。

I have been tracking this same issue down with mongo 2.6.5 on Centos 6.6. The error is coming from /etc/init.d/functions when it is trying to find the program's base name and then subsequently automatically generate a PID file. That's being called by daemon like so:

daemon --user mongod ' /usr/bin/mongod  -f /etc/mongod.conf >/dev/null 2>&1'

The base variable grabs everything after the last slash and the pidfile defaults to base + ".pid". Normally you may execute something like this:

daemon --user nobody /usr/bin/some-service
# base:  some-service
# pid file:  some-service.pid

For mongo, the base variable is set to "null 2>&1" and then running basename null 2>&1 results in the error you are seeing. The easiest way to fix this is to specify the actual binary that you intend to run using the --check command-line argument to daemon . Edit /etc/init.d/mongod and search around line 111:

# Old version
#daemon --user "$MONGO_USER" "$NUMACTL $mongod $OPTIONS >/dev/null 2>&1"

# New, working version
daemon --user "$MONGO_USER" --check "$mongod" "$NUMACTL $mongod $OPTIONS >/dev/null 2>&1"

Without digging too much further into the issue, it looks like this argument is missing due to an oversight.

There's a Jira issue for this bug, here .

They have a nice workaround of changing the REGEX that's used to find the values in the config file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM