[SERVER-27016] mongod.pid is not removed when calling db.shutdownServer(), preventing subsequent init.d start Created: 14/Nov/16  Updated: 06/Feb/23  Resolved: 06/Feb/23

Status: Closed
Project: Core Server
Component/s: Admin, Packaging
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Yoni Douek Assignee: [DO NOT ASSIGN] Backlog - Server Development Platform Team (SDP) (Inactive)
Resolution: Won't Do Votes: 1
Labels: sdp-backlog-purge
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-41877 Pid File Exists Closed
Related
related to SERVER-13607 mongod 2.4.10 does not delete PID fil... Closed
Assigned Teams:
Server Development Platform
Sprint: Build 2016-11-21
Participants:
Story Points: 5

 Description   

We're running mongod as an init.d service (Amazon linux), v.3.2.10 -
no matter how we stop mongod (shutdownServer or "service stop") - on the next start we get:

Error starting mongod. /var/run/mongodb/mongod.pid exists.

We then rm the pid file and start, but this is very annoying.
This did not happen in 3.2.1. Please advise on init.d changes we can apply to fix this.



 Comments   
Comment by Iryna Zhuravlova [ 16/Nov/22 ]

After a careful backlog refinement, the team decided to close this ticket because of its low priority and limited resource capacity. If you believe that this ticket requires additional attention from the team and should be re-opened, feel free to change the status to "Needs Scheduling" and ping me or @alexander.neben

Comment by Ralph Seichter [ 30/Sep/18 ]

I was quite surprised to see this bug is still open in MongoDB 4.0.2 Enterprise, almost two years after it has been filed. Any ideas when this will be fixed? It is highly annoying.

Comment by Leam Hall [ 02/Feb/18 ]

In 3.6.2 for RHEL/CentOS the same issue. With an upgrade from 3.4 to 3.6 several issues prevented mongod from starting via the init script, but the init script failed to remove the pid file.

Comment by Ramon Fernandez Marina [ 27/Jan/17 ]

Hi yoni@appsee.com, unfortunately this ticket is not scheduled to land in a stable release yet. Not removing the pid file when using db.shutdownServer() is intentional (see SERVER-13607), but I do see how the interaction with init scripts adds work for the user (e.g.: users need to add pidfile removal to custom shutdown scripts, or duplicate mongod's logic around pidfile + lockfile in the init script).

I'll ask around to see if the init scripts can be made a bit smarter around this issue. In the mean time, if you're using a modern distribution I'd let init scripts handle the mongod service.

Regards,
Ramón.

Comment by Yoni Douek [ 27/Jan/17 ]

Hey Ramon, Any news on this / chance to squeeze it into 3.2.12?
Very annoying : )

Thanks!

Comment by Yoni Douek [ 14/Nov/16 ]

You are correct, sorry for misleading you.

I assume this is not the expected behavior anyway (3.2.1 worked with shutdownServer).

Another issue is that if there's a problem starting mongod (for example - directory permission issues) - if you start it with init.d - it starts, fails, but the pid is still there and you need to delete it to retry. Worth cleaning on errors too (that's how it was in 3.2.1 also).

Thanks

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

I can reproduce this behavior if I shut down mongod using db.shutdownServer() and then try to start it with init scripts, since it seems the init scripts are the ones removing the pid file.

I am unable to reproduce the behavior you describe when I use only init scripts to start/stop the server.

Comment by Yoni Douek [ 14/Nov/16 ]

Here's our conf file -

replication:
   replSetName: "rsSomething"
 
net:
   port: 27017
 
systemLog:
   destination: file
   path: "/data/mongod.log"
   logAppend: true
   logRotate: rename
 
storage:
   dbPath: "/data"
   # Disable rebuilding incomplete indexes on the next start up
   indexBuildRetry: false
 
processManagement:
   fork: true
   pidFilePath: "/var/run/mongodb/mongod.pid"
 
operationProfiling:
   slowOpThresholdMs: 5000

pidFilePath here is exactly as the one in your init.d script.

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