After a package update to 2.6.6 for MongoDB on a CentOS 6 server, I had a problem restarting the service.
Update: this should now be fixed in SERVER-16081, try a new “yum update
” to download the latest packages.
$ /etc/init.d/mongod restart Stopping mongod: [ OK ] Starting mongod: /usr/bin/dirname: extra operand `2>&1.pid' Try `/usr/bin/dirname --help' for more information. [FAILED]
The error would indicate a problem in the start-up init.d script, given the error around dirname
and extra operands. If we look into the /etc/init.d/mongod
file, we see around line 63 the following command.
$ vim /etc/init.d/mongod ... daemon --user "$MONGO_USER" "$NUMACTL $mongod $OPTIONS >/dev/null 2>&1" ...
The alert that triggers the error into stderr of the init.d script, is the 2>&1
part. It tries to redirect all error output. A quick fix is to modify that line and not redirect stderr output.
$ vim /etc/init.d/mongod ... # Disable the original line and remove the 2>&1 redirection # daemon --user "$MONGO_USER" "$NUMACTL $mongod $OPTIONS >/dev/null 2>&1" daemon --user "$MONGO_USER" "$NUMACTL $mongod $OPTIONS >/dev/null"
But the next MongoDB update will most likely reset your init.d script back to the package defaults, so it’s only a short-term fix.
Now, if your MongoDB isn’t starting, and you see these errors, have a look in your /var/log/mongodb/mongod.log
logfiles. Because the init.d script may throw errors when start/stop/restarting the service, the real error is only logged in the mongod.log
files.
$ grep 'ERROR' /var/log/mongodb/mongod.log ... [initandlisten] ERROR: Insufficient free space for journal files [initandlisten] Please make at least 3379MB available in /var/lib/mongodb/journal or use --smallfiles
So if MongoDB isn’t starting, and you’re seeing a dirname
error in your shell when using the init.d scripts, check the /var/log/mongodb/mongod.log
logs. The error in the init.d script seems to be just that, an error, without any impact.