Skip to content

Add nohup support for MongoDB 8.2+ without --fork flag#916

Open
bruno580 wants to merge 2 commits into
rueckstiess:developfrom
bruno580:fix/mongodb-8.2-fork
Open

Add nohup support for MongoDB 8.2+ without --fork flag#916
bruno580 wants to merge 2 commits into
rueckstiess:developfrom
bruno580:fix/mongodb-8.2-fork

Conversation

@bruno580

Copy link
Copy Markdown

Description of changes

This change simply swaps the --fork flag with nohup for versions of mongod and mongos running on 8.2 and newer to avoid the error below.

BadValue: Server fork+exec via `--fork` or `processManagement.fork` is incompatible with macOS

Testing

Single

└─[130] <git:(fix/mongodb-8.2-fork 36eb6e3✱✈) > python -m mtools.mlaunch.mlaunch init --single
Detected mongod version: 8.2.1
launching: nohup on port 27017

└─[0] <git:(fix/mongodb-8.2-fork 36eb6e3✱✈) > python -m mtools.mlaunch.mlaunch list --verbose
Detected mongod version: 8.2.1

PROCESS    PORT     STATUS     PID      TAGS

single     27017    running    93928    27017, all, mongod, running, single

Replica Set

└─[0] <git:(fix/mongodb-8.2-fork 36eb6e3✱✈) > python -m mtools.mlaunch.mlaunch init --replicaset --nodes 3
Detected mongod version: 8.2.1
launching: nohup on port 27017
launching: nohup on port 27018
launching: nohup on port 27019
replica set 'replset' initialized.

└─[0] <git:(fix/mongodb-8.2-fork 36eb6e3✱✈) > mongosh mongodb://localhost:27017,27018,27019 --quiet --eval "db.version()"
8.2.1

└─[0] <git:(fix/mongodb-8.2-fork 36eb6e3✱✈) > mlaunch list --verbose
Detected mongod version: 8.2.1

PROCESS    PORT     STATUS     PID      TAGS

mongod     27017    running    99672    27017, all, mongod, running
mongod     27018    running    99674    27018, all, mongod, running
mongod     27019    running    99676    27019, all, mongod, running

Sharded cluster

└─[0] <git:(fix/mongodb-8.2-fork 36eb6e3✱✈) > python -m mtools.mlaunch.mlaunch init --replicaset --sharded 2 --config 1 --mongos 1
Detected mongod version: 8.2.1
launching: nohup on port 27018
launching: nohup on port 27019
launching: nohup on port 27020
launching: nohup on port 27021
launching: nohup on port 27022
launching: nohup on port 27023
launching: config server on port 27024
replica set 'configRepl' initialized.
replica set 'shard01' initialized.
replica set 'shard02' initialized.
launching: nohup on port 27017
adding shards. can take up to 30 seconds...

└─[1] <git:(fix/mongodb-8.2-fork 36eb6e3✱✈) > mongosh --quiet --eval "db.version()"
8.2.1

└─[0] <git:(fix/mongodb-8.2-fork 36eb6e3✈) > python -m mtools.mlaunch.mlaunch list --verbose
Detected mongod version: 8.2.1

PROCESS          PORT     STATUS     PID      TAGS

mongos           27017    running    28714    27017, all, mongos, running

config server    27024    running    28665    27024, all, config, mongod, running

shard01
    secondary    27020    running    28657    27020, all, mongod, running, secondary, shard01
    mongod       27018    running    28653    27018, all, mongod, running, shard01
    mongod       27019    running    28655    27019, all, mongod, running, shard01

shard02
    mongod       27021    running    28659    27021, all, mongod, running, shard02
    mongod       27022    running    28661    27022, all, mongod, running, shard02
    mongod       27023    running    28663    27023, all, mongod, running, shard02

O/S testing:

O/S Version(s)
Linux Not tested
macOS Darwin 25.1.0 Darwin Kernel Version 25.1.0: Mon Oct 20 19:32:41 PDT 2025; root:xnu-12377.41.6~2/RELEASE_ARM64_T6000 arm64
Windows N/A

@aconejos

Copy link
Copy Markdown

Please please merge this one! 🙏

@stennie stennie self-assigned this May 20, 2026
@stennie stennie requested a review from Copilot May 20, 2026 23:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates mlaunch process startup command construction to avoid MongoDB 8.2+ failures on macOS caused by --fork by switching to a nohup-based background launch strategy.

Changes:

  • Conditionally replace --fork with nohup ... & for mongod when running MongoDB 8.2+ on non-Windows platforms.
  • Conditionally replace --fork with nohup ... & for mongos when running MongoDB 8.2+ on non-Windows platforms.
  • Add stdout/stderr redirection to /dev/null for the nohup launch path.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread mtools/mlaunch/mlaunch.py
Comment thread mtools/mlaunch/mlaunch.py Outdated
Comment thread mtools/mlaunch/mlaunch.py Outdated
Comment thread mtools/mlaunch/mlaunch.py
Comment on lines +2139 to +2143
# Check if mongod is running on 8.2 or higher
if int(self.current_version.split('.')[0]) >= 9 or (int(self.current_version.split('.')[0]) == 8 and int(self.current_version.split('.')[1]) >= 2):
command_str = ("nohup \"%s\" %s --dbpath \"%s\" --logpath \"%s\" "
"--port %i "
"%s %s > /dev/null 2>&1 &" % (os.path.join(path, 'mongod'), rs_param,

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stennie , do you think we need to add a test case for nohup? From a quick read of test_mlaunch_commandlines.py, it is reading .mlaunch_startup... so it kinda makes sense. I don't think it breaks anything as is though. Any thoughts?

Comment thread mtools/mlaunch/mlaunch.py
Comment thread mtools/mlaunch/mlaunch.py
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants