From fa1787f3efa0b3b06d3cbd91fc6a5add1bee86d6 Mon Sep 17 00:00:00 2001 From: Stephen Steneker Date: Tue, 8 Nov 2022 14:00:32 +1100 Subject: [PATCH] Fix #894: mlaunch init --help should not require mongod --- mtools/mlaunch/mlaunch.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/mtools/mlaunch/mlaunch.py b/mtools/mlaunch/mlaunch.py index 844b9a16..5945ac3d 100755 --- a/mtools/mlaunch/mlaunch.py +++ b/mtools/mlaunch/mlaunch.py @@ -133,7 +133,7 @@ def shutdown_host(port, username=None, password=None, authdb=None): @functools.lru_cache() -def check_mongo_server_output(binary, argument): +def check_mongo_server_output(binary, argument, fatal = True): """Call mongo[d|s] with arguments such as --help or --version. This is used only to check the server's output. We expect the server to @@ -144,9 +144,11 @@ def check_mongo_server_output(binary, argument): stderr=subprocess.STDOUT, stdout=subprocess.PIPE, shell=False) except OSError as exc: - print('Failed to launch %s' % binary) - raise SystemExit(exc) - + if fatal: + print(f"Fatal error: failed to launch [{binary}].\n" + "Please ensure this binary is found in your $PATH " + "or specified with --binarypath.\n") + raise SystemExit(exc) out, err = proc.communicate() if proc.returncode: @@ -201,7 +203,7 @@ def __init__(self, test=False): self.args = dict() self.args['binarypath'] = sys.argv[i+1] break - self.current_version = self.getMongoDVersion() + self.current_version = self.getMongoDVersion(False) def run(self, arguments=None): """ @@ -898,13 +900,13 @@ def init(self): # but with release candidates we get abck something like # "db version v3.4.0-rc2". This code exact the "major.minor.revision" # part of the string - def getMongoDVersion(self): + def getMongoDVersion(self, fatal = True): binary = "mongod" if self.args and self.args.get('binarypath'): binary = os.path.join(self.args['binarypath'], binary) try: - out = check_mongo_server_output(binary, '--version') + out = check_mongo_server_output(binary, '--version', fatal) except Exception: return "0.0.0"