From 705aebd3ebd8511390251c3bfe97b0784e65fb9c Mon Sep 17 00:00:00 2001 From: Robert Thomas <31854736+wolveix@users.noreply.github.com> Date: Sat, 14 Sep 2024 17:41:38 +0100 Subject: [PATCH] Handle stop signal gracefully --- Dockerfile | 2 ++ run.sh | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 983e9ee..d7c657b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -40,6 +40,8 @@ ENV AUTOSAVENUM="5" \ TIMEOUT="30" \ VMOVERRIDE="false" +STOPSIGNAL SIGINT + EXPOSE 7777/udp 7777/tcp ENTRYPOINT [ "/init.sh" ] diff --git a/run.sh b/run.sh index 5f05c9b..f69f739 100755 --- a/run.sh +++ b/run.sh @@ -104,4 +104,15 @@ fi cd /config/gamefiles || exit 1 -exec ./FactoryServer.sh -Port="$SERVERGAMEPORT" "${ini_args[@]}" "$@" +./FactoryServer.sh -Port="$SERVERGAMEPORT" "${ini_args[@]}" "$@" & + +sleep 2 +satisfactory_pid=$(ps --ppid ${!} o pid=) + +shutdown() { + printf "\\nReceived SIGINT. Shutting down.\\n" + kill -INT $satisfactory_pid 2>/dev/null +} +trap shutdown SIGINT SIGTERM + +wait