From ed6fc1af16d7ccf52621f46625a08787951b2233 Mon Sep 17 00:00:00 2001 From: Salt Date: Wed, 12 May 2021 22:41:01 -0500 Subject: [PATCH] Add trap to gracefully cleanup, add screen session --- Dockerfile | 2 +- start-server.sh | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index e2fcdaa..81b2fe0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,7 @@ RUN apk add curl openjdk8-jre &&\ # The second stage is the actual container FROM openjdk:8 -RUN apt-get update && apt-get install rsync -y +RUN apt-get update && apt-get install rsync screen -y WORKDIR /minecraft COPY --from=build /minecraft . CMD [ "bash", "start-server.sh" ] diff --git a/start-server.sh b/start-server.sh index c1bef15..efdac89 100755 --- a/start-server.sh +++ b/start-server.sh @@ -1,4 +1,4 @@ -#! /bin/sh +#! /bin/bash # # start-server.sh # Copyright (C) 2021 Vintage Salt @@ -33,5 +33,10 @@ java -version echo "Invoking java with args: $args" # Start 'er up -java $args +cleanup() { + screen -p 0 -S minecraft -X stuff save-all^M + screen -p 0 -S minecraft -X stuff stop^M +} +trap cleanup EXIT +screen -DmS minecraft java $args