This commit is contained in:
Kris Lamoureux 2024-05-12 23:55:42 -04:00
parent 381bd9eeff
commit a05eaa5211
5 changed files with 55 additions and 4 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
data data
.env .env
screenlog.0

View File

@ -10,7 +10,7 @@ RUN groupadd -g 1000 minecraft && \
# Install scripting dependencies # Install scripting dependencies
RUN apt-get update && \ RUN apt-get update && \
apt-get install -y curl gpg jq screen && \ apt-get install -y curl gpg jq procps screen && \
apt-get clean && \ apt-get clean && \
rm -rf /var/lib/apt/lists/* rm -rf /var/lib/apt/lists/*

18
Makefile Normal file
View File

@ -0,0 +1,18 @@
CONTAINER = minecraft-minecraft-1
.PHONY: default build clean install
default: build
build:
docker compose build
clean:
rm screenlog.0
docker compose down --rmi all
docker builder prune -f
install: build
touch screenlog.0
docker compose up -d
sleep 2
docker logs -f $(CONTAINER)

View File

@ -12,8 +12,10 @@ services:
image: ${IMAGE:-minecraft}:${TAG:-latest} image: ${IMAGE:-minecraft}:${TAG:-latest}
ports: ports:
- "0.0.0.0:25565:25565" - "0.0.0.0:25565:25565"
#volumes: volumes:
# - minecraft:/app/world - type: bind
source: ./screenlog.0
target: /app/screenlog.0
environment: environment:
EULA: "${EULA:-false}" EULA: "${EULA:-false}"
DEBUG: "${DEBUG:-false}" DEBUG: "${DEBUG:-false}"

View File

@ -46,6 +46,9 @@ fi
# Pre-create the screen log # Pre-create the screen log
touch screenlog.0 touch screenlog.0
# Set up a SIGTERM signal trap
trap 'kill ${TAIL_PID}' SIGTERM
# Run server in screen (without attaching) # Run server in screen (without attaching)
/usr/bin/screen -dmS minecraft -L \ /usr/bin/screen -dmS minecraft -L \
bash -c " bash -c "
@ -54,6 +57,33 @@ touch screenlog.0
/usr/bin/java $JVM_OPTS -jar server.jar --nogui /usr/bin/java $JVM_OPTS -jar server.jar --nogui
" "
# Get screen PID
SCREEN_PID="$(
screen -ls | grep -oE '[0-9]+\.minecraft' | cut -d. -f1
)"
# Check screen PID
if ! ps -p "$SCREEN_PID" > /dev/null; then
echo "[ERROR] Could not obtain screen PID: \"$SCREEN_PID\""
screen -ls
echo now testing:
screen -ls | grep -oE '[0-9]+\.minecraft' | cut -d. -f1
exit 1
fi
# Tail screen log to container stdout # Tail screen log to container stdout
[ "$DEBUG" = "true" ] && echo "[DEBUG] Tailing screenlog.0" [ "$DEBUG" = "true" ] && echo "[DEBUG] Tailing screenlog.0"
tail -f screenlog.0 tail -f screenlog.0 &
TAIL_PID=$!
wait "$TAIL_PID"
if screen -ls | grep -q minecraft; then
echo "[INFO] Stopping minecraft"
/usr/bin/screen -p 0 -S minecraft -X eval 'stuff "stop"\015'
else
echo "[WARN]: 'minecraft' screen not found attempting to stop server"
return 1
fi
wait "$SCREEN_PID"