diff --git a/esrally/mechanic/launcher.py b/esrally/mechanic/launcher.py index db77f1cc7..c4f1f55d3 100644 --- a/esrally/mechanic/launcher.py +++ b/esrally/mechanic/launcher.py @@ -16,6 +16,8 @@ # under the License. import logging import os +import shlex +import subprocess import psutil @@ -186,6 +188,21 @@ def _set_env(self, env, k, v, separator=' ', prepend=False): else: env[k] = env[k] + separator + v + @staticmethod + def _run_subprocess(command_line, env): + command_line_args = shlex.split(command_line) + + # pylint: disable=subprocess-popen-preexec-fn + with subprocess.Popen(command_line_args, + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + universal_newlines=True, + env=env, + preexec_fn=os.setpgrp) as command_line_process: + # wait for it to finish + command_line_process.poll() + return command_line_process.returncode + @staticmethod def _start_process(binary_path, env): if os.name == "posix" and os.geteuid() == 0: @@ -193,7 +210,7 @@ def _start_process(binary_path, env): os.chdir(binary_path) cmd = [io.escape_path(os.path.join(".", "bin", "elasticsearch"))] cmd.extend(["-d", "-p", "pid"]) - ret = process.run_subprocess_with_logging(command_line=" ".join(cmd), env=env, detach=True) + ret = ProcessLauncher._run_subprocess(command_line=" ".join(cmd), env=env) if ret != 0: msg = "Daemon startup failed with exit code [{}]".format(ret) logging.error(msg) diff --git a/tests/mechanic/launcher_test.py b/tests/mechanic/launcher_test.py index 60c3417b4..0bab38e89 100644 --- a/tests/mechanic/launcher_test.py +++ b/tests/mechanic/launcher_test.py @@ -106,6 +106,9 @@ def __init__(self, *args, **kwargs): def communicate(self, input=None, timeout=None): return [b"", b""] + def poll(self): + pass + def __enter__(self): return self