[SERVER-16081] init.d mongod startup script fails, with dirname message Created: 11/Nov/14  Updated: 06/Apr/23  Resolved: 23/Dec/14

Status: Closed
Project: Core Server
Component/s: Packaging
Affects Version/s: 2.6.4, 2.6.5, 2.6.6
Fix Version/s: 2.6.7, 2.8.0-rc4

Type: Bug Priority: Minor - P4
Reporter: Alberto Matsuchita Assignee: Ernie Hershey
Resolution: Done Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Zip Archive Config.zip     Text File bash_cmd.txt    
Issue Links:
Duplicate
is duplicated by SERVER-16240 RHEL sysvinit script causes error on ... Closed
Backwards Compatibility: Fully Compatible
Operating System: Linux
Backport Completed:
Sprint: BUILD 1
Participants:

 Description   

Hi, when I start mongodb 2.6.4.X and 2.6.5.X in

LSB_VERSION=base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Oracle Linux Server release 6.6
Red Hat Enterprise Linux Server release 6.6 (Santiago)
Oracle Linux Server release 6.6

I receive the messages:

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

But MongoDb still starts.

I´d like to know if there is a workaround or some correction and if these message causes no problem.

Thanks in advance. Alberto



 Comments   
Comment by Githook User [ 06/Jan/15 ]

Author:

{u'username': u'ehershey', u'name': u'Ernie Hershey', u'email': u'ernie.hershey@10gen.com'}

Message: SERVER-16081 add --check to init script daemon command

(cherry picked from commit 6105f06402fe1e7578d41f3e4e583a1476ef2455)
Branch: v2.6
https://github.com/mongodb/mongo/commit/844d4b6bf595394e18f39921fc1c9e51f1c45379

Comment by Smowtion [ 24/Dec/14 ]

Mongodb 2.64 not work with the bug fix, but 2.6.6 sucessfull

Comment by Githook User [ 23/Dec/14 ]

Author:

{u'username': u'ehershey', u'name': u'Ernie Hershey', u'email': u'ernie.hershey@10gen.com'}

Message: SERVER-16081 add --check to init script daemon command
Branch: master
https://github.com/mongodb/mongo/commit/6105f06402fe1e7578d41f3e4e583a1476ef2455

Comment by Ernie Hershey [ 23/Dec/14 ]

Tested on these OS's

  1. rhel 5.5
  2. rhel 5.11
  3. rhel 6.2
  4. rhel 6.6 (also reproduced the error before verifying the fix)
  5. rhel 7.0 (despite using systemd)
  6. Amazon Linux 2013.03 (version we build on)
  7. Amazon Linux 2014.09 (latest)

I skipped sles because it uses a different init script daemon wrapper which doesn't support or need the --check option.

Comment by Ernie Hershey [ 23/Dec/14 ]

I'm going to test the fix on these platforms to verify:

  1. rhel 5.5
  2. rhel 6.2
  3. rhel 6.6
  4. rhel 7.0 (despite using systemd)
  5. sles 11
  6. Amazon linux - latest version
Comment by Ville-Pekka Vainio [ 19/Dec/14 ]

Just a note that currently mongod does not even start on CentOS/RHEL 6.6 without the proposed patch.

Comment by Ramon Fernandez Marina [ 18/Dec/14 ]

Thanks for the additional information mvatanen. All, this ticket has already been confirmed as a bug (indicated by the "Needs Triage" fixVersion) and will be included in the planing for future releases. Feel free to watch it to receive updates.

Regards,
Ramón.

Comment by Mikko Vatanen [ 16/Dec/14 ]

We have the same issue with MongoDB v2.6.5. Both CentOS 6.6 (Final) and RHEL 6.6 (Santiago) are affected.

Tracing /etc/init.d/mongod shows that parsing $base variable is failing at /etc/init.d/functions:421.

        # Save basename.
        [ -z "$gotbase" ] && base=${1##*/}

This causes dirname command at /etc/init.d/functions.py:151 to print error message:

 
[root@dev mongo]# bash -x /etc/init.d/mongod restart
 
[... cut ...]
 
+ echo -n 'Starting mongod: '
Starting mongod: + daemon --user mongod ' /usr/bin/mongod  -f /etc/mongod.conf >/dev/null 2>&1'
+ local gotbase= force= nicelevel corelimit
+ local pid base= user= nice= bg= pid_file=
+ local cgroup=
+ nicelevel=0
+ '[' --user '!=' -user ']'
+ case $1 in
+ user=mongod
+ shift 2
+ '[' ' /usr/bin/mongod  -f /etc/mongod.conf >/dev/null 2>&1' '!=' ' /usr/bin/mongod  -f /etc/mongod.conf >/dev/null 2>&1' ']'
+ '[' -z '' ']'
+ base='null 2>&1'
+ __pids_var_run 'null 2>&1' ''
+ local 'base=null 2>&1'
+ local 'pid_file=/var/run/null 2>&1.pid'
++ /usr/bin/dirname /var/run/null '2>&1.pid'
/usr/bin/dirname: extra operand `2>&1.pid'
Try `/usr/bin/dirname --help' for more information.
+ local pid_dir=
+ local binary=
 
[... cut ...]

Here is test case for the $base variable:

[root@dev mongo]# FOO='/usr/bin/mongod  -f /etc/mongod.conf >/dev/null 2>&1'
[root@dev mongo]# echo ${FOO##*/}
null 2>&1

Setting the $base variable is failing because expansion pattern does not expect any slash after "/usr/bin/mongod" part.

Fortunately the previously proposed patch SERVER-16240 seems to solve this issue.

--- /etc/init.d/mongod	2014-10-08 20:29:50.000000000 +0300
+++ /etc/init.d/mongod.patch	2014-12-16 15:40:31.848352072 +0200
@@ -27,6 +27,7 @@
 PIDDIR=`dirname $PIDFILE`
 
 mongod=${MONGOD-/usr/bin/mongod}
+servicename=mongod
 
 MONGO_USER=mongod
 MONGO_GROUP=mongod
@@ -63,7 +64,7 @@
   ulimit -u 32000
 
   echo -n $"Starting mongod: "
-  daemon --user "$MONGO_USER" "$NUMACTL $mongod $OPTIONS >/dev/null 2>&1"
+  daemon --check $servicename --user "$MONGO_USER" "$NUMACTL $mongod $OPTIONS >/dev/null 2>&1"
   RETVAL=$?
   echo
   [ $RETVAL -eq 0 ] && touch /var/lock/subsys/mongod

Test run with patched version:

[root@dev mongo]# bash -x /etc/init.d/mongod.patch restart
 
[...cut...]
 
+ echo -n 'Starting mongod: '
Starting mongod: + daemon --check mongod --user mongod ' /usr/bin/mongod  -f /etc/mongod.conf >/dev/null 2>&1'
+ local gotbase= force= nicelevel corelimit
+ local pid base= user= nice= bg= pid_file=
+ local cgroup=
+ nicelevel=0
+ '[' --check '!=' -check ']'
+ case $1 in
+ base=mongod
+ gotbase=yes
+ shift 2
+ '[' --user '!=' -user ']'
+ case $1 in
+ user=mongod
+ shift 2
+ '[' ' /usr/bin/mongod  -f /etc/mongod.conf >/dev/null 2>&1' '!=' ' /usr/bin/mongod  -f /etc/mongod.conf >/dev/null 2>&1' ']'
+ '[' -z yes ']'
+ __pids_var_run mongod ''
+ local base=mongod
+ local pid_file=/var/run/mongod.pid
++ /usr/bin/dirname /var/run/mongod.pid
+ local pid_dir=/var/run
+ local binary=
 
[...cut...]

Comment by Wahyu Kristianto [ 15/Dec/14 ]

If I remove this ">/dev/null 2>&1", mongod work. But, get this message :

# sudo service mongod start
Starting mongod: about to fork child process, waiting until server is ready for connections.
forked process: 2039
child process started successfully, parent exiting
                                                           [  OK  ]
# sudo service mongod status
mongod (pid 4050) is running...

  1. CentOS release 6.6 (Final)
  2. MongoDB version: 2.6.6
  3. Output
Comment by Ramon Fernandez Marina [ 15/Dec/14 ]

kristories, in order to determine what's causing this error message we'll need some more information:

  1. The platform you're using (OS and version)
  2. The version of MongoDB
  3. The output of running the following commands are root on the shell (add sudo if needed):

    bash -x /etc/init.d/mongod stop
    bash -x /etc/init.d/mongod start

Comment by Wahyu Kristianto [ 15/Dec/14 ]

Hi Ramon,
I get this message after changing mongod

# sudo service mongod start
Starting mongod: /usr/bin/dirname: extra operand `-f'
Try `/usr/bin/dirname --help' for more information.
                                                           [  OK  ]
# sudo service mongod status
mongod dead but subsys locked

Comment by Alberto Matsuchita [ 18/Nov/14 ]

Thank you very much for your return and support. Alberto

Comment by Ramon Fernandez Marina [ 17/Nov/14 ]

Thanks for additional information amatsuchita. The error message you're seeing is harmless and you can safely ignore it.

The message appears because /etc/init.d/mongod launches mongod in a way that doesn't agree with what the daemon function expects, and daemon complains about it.

There's another consequence of this issue, and is that RedHat's init scripts can't check whether mongod is already running. If one tries to launch a second mongod with the same configuration file the system should just ignore the request and continue quietly, but in this case an error is produced – since the system can't tell that mongod is already running it tries to launch a second one, but mongod finds that there's another mongod process running on the same database path and aborts with an error. This error is passed back to the system and it's visible to the user.

That being said, the total user impact is minimal, and mostly cosmetic. To get rid of the error, a possible workaround is to edit /etc/init.d/mongod and replace:

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

with

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

Please note that this workaround still doesn't 100% conform to daemon's spec, and it may get overwritten when you upgrade to the next version of MongoDB.

We're keeping this ticket to investigate what can we do to improve the integration with RedHat's init.d functions.

Regards,
Ramón.

Comment by Alberto Matsuchita [ 17/Nov/14 ]

Hi.

I have attached the command execution outputs.

Thank you

Comment by Ramon Fernandez Marina [ 14/Nov/14 ]

amatsuchita, nothing looks out of place in the files you sent. Can you please run the following as root:

bash -x /etc/init.d/mongod stop
bash -x /etc/init.d/mongod start

and paste the output on this ticket? Hopefully we'll be able to see where spurious message is coming from.

Thanks,
Ramón.

Comment by Alberto Matsuchita [ 12/Nov/14 ]

/etc/sysconfig/mongod renamed to mongod.txt (it is the original. nothing was added).
Configs where added in /etc/mongd.conf which is attached.
thank you

Comment by Ramon Fernandez Marina [ 11/Nov/14 ]

Can you please paste the contents of /etc/mongod.conf and /etc/sysconfig/mongod? If you're using a custom configuration file, please send that instead of mongod.conf.

Thanks,
Ramón.

Generated at Thu Feb 08 03:39:54 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.