10

I am trying to figure out why the provided init.d script is not working on CentOS. I tried starting it manually:

/etc/init.d/mongod start

But I get the following error:

Starting mongod: /usr/bin/dirname: extra operand `2>&1.pid'
Try `/usr/bin/dirname --help' for more information.

I looked in the script where it tries to start:

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

So I looked where mongod var is defined:

mongod=${MONGOD-/usr/bin/mongod}

Also tried:

service mongod start

Same error.

Not sure what I have setup wrong, but I have verified that I have the latest script but I cannot get mongod process to start.

Any ideas???

lostintranslation
  • 23,756
  • 50
  • 159
  • 262

5 Answers5

1

The following link appears to address the issue well https://ma.ttias.be/mongodb-startup-dirname-extra-operand-pid/

In a nutshell, a bad script appears to have been distributed but the output it produces is not harmful, mongod still runs. If you run yum update you'll get a fixed script, but likely mongod will still fail because the script was not making it fail. Check your mongo logs (usually /var/log/mongodb/mongod.log, but can be different if specified in differently in /etc/mongod.conf). The log file should tell you the real reason it's failing.

David Sacks
  • 6,366
  • 1
  • 15
  • 7
0

Check the mongo pid file location in the config file /etc/mongod.conf:

awk -F'[:=]' -v IGNORECASE=1 '/^[[:blank:]]*pidfilepath[[:blank:]]*[:=][[:blank:]]*/{print $2}' /etc/mongod.conf

By default there should be this line in mongod.conf: 'pidfilepath = /var/run/mongodb/mongod.pid'. Add it if it doesn't exist.

If you are using the YAML version of /etc/mongod.conf, check out this issue: https://jira.mongodb.org/browse/SERVER-13595. In short, you need to change this line in /etc/rc.d/init.d/mongod:

PIDFILE=`awk -F= '/^pidfilepath[[:blank:]]*=[[:blank:]]*/{print $2}' "$CONFIGFILE"`

to:

PIDFILE=`awk -F: '/^[[:blank:]]*pidFilePath[[:blank:]]*:[[:blank:]]*/{print $2}' "$CONFIGFILE" | tr -d ' '`
anhlc
  • 13,839
  • 4
  • 33
  • 40
  • Cool, thanks I will try that. Quick note I can start mongod manually with my config file as well. mongod -f /etc/mongod.conf. Doesn't seem like a conf file issue, more so a init.d script issue. Also the Starting mongod: /usr/bin/dirname error is troublesome, should be trying to start /usr/bin/mongod, /usr/bin/dirname seems like a script variable is screwed up. – lostintranslation Nov 06 '14 at 17:34
0

For me problem was in pidfilepath. Init script can't deal with path in format like this

pidfilepath = /var/run/mongodb/mongod.pid

PIDFILE variable inside of init script contains ' /var/run/mongodb/mongod.pid' and not '/var/run/mongodb/mongod.pid'

FIX: replace PIDFILE line with this and it will work.

PIDFILE=awk -F= '/^pidfilepath[[:blank:]]*=[[:blank:]]*/{gsub(" ", "", $2);print $2}' "$CONFIGFILE"

haad
  • 1
  • 1
0

I have also faced the same issue.

The fix is to make a small change in the script file(/etc/init.d/mongod) as mentioned below:

line 63 i guess:

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

to

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

Hope this helps !!!

Jerry
  • 7,863
  • 2
  • 26
  • 35
-1

It could be a RedHat bug on the initscript package: goog.le forum redhat bugzilla

DFE
  • 51
  • 1
  • 6