[SERVER-12048] Calling "service mongod start" with mongod running prevents "service mongod stop" from working Created: 11/Dec/13  Updated: 07/Apr/23  Resolved: 25/Aug/16

Status: Closed
Project: Core Server
Component/s: Packaging
Affects Version/s: 2.5.5
Fix Version/s: 3.0.13, 3.2.10, 3.3.12

Type: Bug Priority: Major - P3
Reporter: Ernie Hershey Assignee: Brian Samek
Resolution: Done Votes: 2
Labels: code-only
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Tested in centos 6


Issue Links:
Duplicate
is duplicated by SERVER-24583 Running "service mongod start" more t... Closed
Related
is related to SERVER-26575 Unable to start mongod service when o... Closed
Backwards Compatibility: Fully Compatible
Operating System: Linux
Backport Completed:
Steps To Reproduce:
  1. install mongodb-org-unstable-server package
  2. run "sudo service mongod start"
  3. run "sudo service mongod start"
  4. run "sudo service mongod stop"
Sprint: Build 17 (07/15/16), Build 18 (08/05/16), Build 2016-08-26
Participants:

 Description   

Running the init script to start the server while it's already running prevents stopping the server with the init script from working.

I could not reproduce this with server 2.4.8



 Comments   
Comment by Githook User [ 29/Aug/16 ]

Author:

{u'username': u'bsamek', u'name': u'Brian Samek', u'email': u'brian.samek@mongodb.com'}

Message: SERVER-12048 Don't start mongod if pidfile exists
Branch: v3.0
https://github.com/mongodb/mongo/commit/4f52ad46435d9f3776e0d37dca26cec1b9fc9ab8

Comment by Githook User [ 29/Aug/16 ]

Author:

{u'username': u'bsamek', u'name': u'Brian Samek', u'email': u'brian.samek@mongodb.com'}

Message: SERVER-12048 Don't start mongod if pidfile exists
Branch: v3.2
https://github.com/mongodb/mongo/commit/133c8ccd7922518785f4086eb172c23dcdb24d82

Comment by Githook User [ 25/Aug/16 ]

Author:

{u'username': u'bsamek', u'name': u'Brian Samek', u'email': u'brian.samek@mongodb.com'}

Message: SERVER-12048 Don't start mongod if pidfile exists
Branch: master
https://github.com/mongodb/mongo/commit/3eaf36bc9fb28f9ca63b0d7de33e9f587aa88325

Comment by jonathanv [ 10/Oct/15 ]

FWIW, I am experiencing the same thing on ubuntu 12, however this happens on the first run of `service mongod start`.

it looks like process id that ran `service mongod start` is written to /var/run , but the actual process id of the mongod seems to be 2 numbers higher.

this wasn't on a fresh install. i upgraded from 2.x. but it looks like all my init/config scripts were correctly cleared out and replaced.

Comment by Ryan Nitz [ 11/Feb/14 ]

I can reproduce this with 2.4.9.

To fix, check for the lock file first on start (in the init script). If the lock file is present then error out to the user saying that it is already running. If the server is not running, but there is a lock file, they will have to manually remove the file before restarting.

When you start the server (again) mongod stomps on the pid file which causes the problem shutting down the server.

If you are stuck with this, and do not want to restart your server, add the pid of the mongod process to whatever you configured the pid file to be (pidfilepath).

Another potential problem is that the script uses killproc. If you are running multiple mongod processes on the same box, this could kill the wrong process. As a hack, I did something like the following in chef to avoid collision (and changed the mongod-test init script to use the binary of /usr/bin/dbtest/mongod):

remote_file "/usr/bin/dbtest/mongod" do
owner 'root'
group 'root'
mode 0755
source "file:///usr/bin/mongod"
action :create
end

http://www.met.reading.ac.uk/it/cgi-bin/man.cgi?section=8&topic=killproc

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