[SERVER-23830] On RHEL7/Centos7 mongod can't stop if pid location in conf differs from the init.d script Created: 20/Apr/16  Updated: 23/Nov/16  Resolved: 13/Jul/16

Status: Closed
Project: Core Server
Component/s: Admin
Affects Version/s: None
Fix Version/s: 3.0.13, 3.2.9, 3.3.10

Type: Bug Priority: Major - P3
Reporter: Davenson Lombard Assignee: Ernie Hershey
Resolution: Done Votes: 1
Labels: code-only
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-24295 mongod service pid is different in /v... Closed
Related
Backwards Compatibility: Fully Compatible
Backport Completed:
Sprint: Build 15 (06/03/16), Build 16 (06/24/16), Build 17 (07/15/16)
Participants:

 Description   

In Centos 7.2 (did not test on other versions), if we modify the pidfilepath in the mongod.conf, the mongod service cannot be stopped. The solution was to change the pidfilepath in the /etc/init.d/mongod file.

Steps to reproduce the issue

  1. Stop mongod if running.
  2. Change the location of pidfilepath to something else
  3. Launch mongod

    sudo service mongod start
    

  4. Stop mongod

    sudo service mongod stop
    

    It will return OK:

    Stopping mongod (via systemctl):                           [  OK  ]

  5. do a ps -ef | grep mongod. Mongod will still be there running.

Solution

  • Edit the init.d script or the mongod.conf file so that the pidfilepath matches in both locations.

Thank you,

Davenson Lombard



 Comments   
Comment by Githook User [ 13/Jul/16 ]

Author:

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

Message: SERVER-23830 Remove hardcoded pidfile path in init script header

This is a small change, the only affect of which is that systemd's
sysvinit compatibility implementation stops assuming this value for
the pidfile on rhel 7 and detects the pid automatically. For SUSE,
there's a separate init.d script. For non-systemd systems, the init
script parses mongod.conf for the pidfile.

(cherry picked from commit b68339f58d1168569ac46e8749429dd26e73748f)
Branch: v3.0
https://github.com/mongodb/mongo/commit/ef8159474d3871307cdfcf70e72e759d123cfa61

Comment by Githook User [ 13/Jul/16 ]

Author:

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

Message: SERVER-23830 Remove hardcoded pidfile path in init script header

This is a small change, the only affect of which is that systemd's
sysvinit compatibility implementation stops assuming this value for
the pidfile on rhel 7 and detects the pid automatically. For SUSE,
there's a separate init.d script. For non-systemd systems, the init
script parses mongod.conf for the pidfile.

(cherry picked from commit b68339f58d1168569ac46e8749429dd26e73748f)
Branch: v3.2
https://github.com/mongodb/mongo/commit/365b9a6508f6fefd0dc28b70a39d68c969b22f40

Comment by Githook User [ 13/Jul/16 ]

Author:

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

Message: SERVER-23830 Remove hardcoded pidfile path in init script header

This is a small change, the only affect of which is that systemd's
sysvinit compatibility implementation stops assuming this value for
the pidfile on rhel 7 and detects the pid automatically. For SUSE,
there's a separate init.d script. For non-systemd systems, the init
script parses mongod.conf for the pidfile.
Branch: master
https://github.com/mongodb/mongo/commit/b68339f58d1168569ac46e8749429dd26e73748f

Comment by Ernie Hershey [ 24/Jun/16 ]

if I remove that line, the following works:

  1. Stopping and starting the service without modifying the config file
  2. Stopping and starting the service with an updated processManagement.pidFilePath value in /etc/mongod.conf

This does not work, but I don't think it doesn't on any system -

  1. Start service
  2. Update processManagement.pidFilePath value in /etc/mongod.conf
  3. Stop service (shows as stopped but process is still running)

I'm going to test a bit more and try to determine if these header comments are used for anything.

Comment by Ernie Hershey [ 22/Jun/16 ]

If I remove the "# pidfile" comment in the init script, I have better luck in systemd with a modifed /etc/mongod.conf.

I can see that systemctl tends to generally automatically update /run/systemd/generator.late/mongod.service to match the comment header contents of /etc/mongod.conf, with or without the pidfile comment, more or less every time I run it.

I'm going to try more testing without the line in the init script and make sure other things still work as expected. If that's the only fix, it's pleasantly small and simple.

Comment by Ernie Hershey [ 19/May/16 ]

Some additional docs on how this works. Maybe there's a way to re-generate the compatibility service systemd is using and have it pick up the new pid file path -

http://unix.stackexchange.com/questions/233468/how-does-systemd-use-etc-init-d-scripts
https://www.freedesktop.org/software/systemd/man/systemd-sysv-generator.html
https://www.freedesktop.org/software/systemd/man/systemd.generator.html

Comment by Ramon Fernandez Marina [ 18/May/16 ]

Looks like systemd indeed parses the init script to find pidfile. If I change both pidFilePath in /etc/mongod.conf and pidfile in /etc/init.d/mongod then things work as expected.

Comment by Ernie Hershey [ 20/Apr/16 ]

Hi - can you let me know what version of mongodb you're using? Also can you post your modified mongod.conf?

This line in the init script should be picking up the pid file path from your config file.

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