diff --git a/launch.py b/launch.py index 9a2ed83..e24d342 100644 --- a/launch.py +++ b/launch.py @@ -2,7 +2,13 @@ import os import random import re +import shlex +import signal import subprocess +import sys + +# On SIGTERM, raise KeyboardInterrupt instead of exiting abruptly. +signal.signal(signal.SIGTERM, signal.default_int_handler) CONFIG_GENERATED = "/reforger/Configs/docker_generated.json" @@ -179,18 +185,35 @@ def bool_str(text): config_path = CONFIG_GENERATED -launch = " ".join( - [ - os.environ["ARMA_BINARY"], - f"-config {config_path}", - "-backendlog", - "-nothrow", - f"-maxFPS {os.environ['ARMA_MAX_FPS']}", - f"-profile {os.environ['ARMA_PROFILE']}", - f"-addonDownloadDir {os.environ['ARMA_WORKSHOP_DIR']}", - f"-addonsDir {os.environ['ARMA_WORKSHOP_DIR']}", - os.environ["ARMA_PARAMS"], - ] -) -print(launch, flush=True) -os.system(launch) +launch = [ + os.environ["ARMA_BINARY"], + "-config", + config_path, + "-backendlog", + "-nothrow", + "-maxFPS", + os.environ["ARMA_MAX_FPS"], + "-profile", + os.environ["ARMA_PROFILE"], + "-addonDownloadDir", + os.environ["ARMA_WORKSHOP_DIR"], + "-addonsDir", + os.environ["ARMA_WORKSHOP_DIR"], + *shlex.split(os.environ["ARMA_PARAMS"]), +] + +print(shlex.join(launch), flush=True) + +proc = subprocess.Popen(launch) + +try: + try: + sys.exit(proc.wait()) + except KeyboardInterrupt: + proc.send_signal(signal.SIGINT) + sys.exit(proc.wait()) +except SystemExit: + raise +except BaseException: + proc.kill() + raise