[SERVER-36043] systemd unit for mongod starts before multi.user target Created: 10/Jul/18  Updated: 29/Oct/23  Resolved: 08/Aug/18

Status: Closed
Project: Core Server
Component/s: Packaging
Affects Version/s: None
Fix Version/s: 3.4.22, 3.6.14, 4.1.2, 4.0.11

Type: Bug Priority: Major - P3
Reporter: Miguel Angel Nieto Assignee: Mathew Robinson (Inactive)
Resolution: Fixed Votes: 0
Labels: build-planned
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Problem/Incident
causes SERVER-42603 Recent service file change may cause ... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v4.0
Sprint: Build 2018-08-13
Participants:
Case:
Story Points: 1

 Description   

The mongod service unit is configured to be part of the multi-user.target, but the unit configuration also has the following parameter:

After=network.target

Basically, this makes mongod start just after the network is up and not during multi-user (one of the latest targets to trigger). This causes problems on those servers where there are network storage services or authentication services (like AD) still pending to start. mongod would not be able to start if it depends on them.

Removing the After parameter would make systemd to start mongod as part of the correct target. If an After is needed for some reason, After=multi-user.target would avoid most of the problems with dependencies between services.

Affects all native packages (RPM and DEB) for systemd based Linux distros.



 Comments   
Comment by Connecting Media [ 09/Aug/19 ]

@Mikko Tommila see SERVER 42603, which pointed out even worse problems with that change. And by now the change has been reverted and is expected to be released in 4.0.12.

Comment by Mikko Tommila [ 09/Aug/19 ]

In a cloud deployment (e.g. AWS EC2) the cloud-init script runs before "multi-user.target". If the cloud-init script depends on MongoDB already running, then this change breaks the functionality when upgrading from 4.0.10 to 4.0.11. In version 4.0.10 the cloud-init just works, but in 4.0.11 the cloud-init waits for MongoDB to be available, but it will never be available, as MongoDB now only starts after the cloud-init script finishes.

Comment by Connecting Media [ 05/Aug/19 ]

This is frankly incorrect. And in itself breaks and creates a cyclic dependency on itself.

"After" doesn't control to which start group a service belongs. "WantedBy" does. And that is already set to "multi-user.target"
Setting both "After" and "WantedBy" means mongod is supposed to start before and after "multi-user.target". Which in turn caused SERVER-42603.

The proper solution is that if you have services that need to start before mongod, add "Before=mongod.service" to their service files. The way mongod was started before was the recommended way and nothing needs to change. It is part of the correct start group and starting it after the "network.target" is also correct, because mongod needs networking to be available.

So it was right before. And the misconfiguration is not on the Mongo side.

Comment by Githook User [ 07/Jun/19 ]

Author:

{'name': 'Mathew Robinson', 'email': 'chasinglogic@gmail.com', 'username': 'chasinglogic'}

Message: SERVER-36043 Start mongod after multi-user.target

(cherry picked from commit a014dce43e6f55fd6611a865902e46b34953ad72)
Branch: v3.4
https://github.com/mongodb/mongo/commit/c1f294711b61ef5e582592230531cc1d6d720f2b

Comment by Githook User [ 07/Jun/19 ]

Author:

{'name': 'Mathew Robinson', 'email': 'chasinglogic@gmail.com', 'username': 'chasinglogic'}

Message: SERVER-36043 Start mongod after multi-user.target

(cherry picked from commit a014dce43e6f55fd6611a865902e46b34953ad72)
Branch: v3.6
https://github.com/mongodb/mongo/commit/495c48d81e6be6d876b7b2429a83a3ccf9de6fa5

Comment by Githook User [ 07/Jun/19 ]

Author:

{'name': 'Mathew Robinson', 'email': 'chasinglogic@gmail.com', 'username': 'chasinglogic'}

Message: SERVER-36043 Start mongod after multi-user.target

(cherry picked from commit a014dce43e6f55fd6611a865902e46b34953ad72)
Branch: v4.0
https://github.com/mongodb/mongo/commit/39e93638435616be15ec31bb8863dbec6def9f36

Comment by Githook User [ 08/Aug/18 ]

Author:

{'name': 'Mathew Robinson', 'email': 'chasinglogic@gmail.com', 'username': 'chasinglogic'}

Message: SERVER-36043 Start mongod after multi-user.target
Branch: master
https://github.com/mongodb/mongo/commit/a014dce43e6f55fd6611a865902e46b34953ad72

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