Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix non-graceful server shutdowns and improve signal handling #41

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
53 changes: 38 additions & 15 deletions launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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