Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
dab509a234 |
14
Makefile
14
Makefile
@ -61,34 +61,34 @@ define copy_build_files
|
||||
sed -i 's/EULA=true/EULA=false/' "$${TEMP_DEST_FILE}"; \
|
||||
fi; \
|
||||
if cmp -s "$${SRC_FILE}" "$${TEMP_DEST_FILE}"; then \
|
||||
echo "INFO: \"$${DEST_FILE}\" is up to date."; \
|
||||
echo "[INFO]: \"$${DEST_FILE}\" is up to date."; \
|
||||
rm "$${TEMP_DEST_FILE}"; \
|
||||
else \
|
||||
echo "ERROR: \"$${DEST_FILE}\" is different from \"$${SRC_FILE}\""; \
|
||||
echo "[ERROR]: \"$${DEST_FILE}\" is different from \"$${SRC_FILE}\""; \
|
||||
diff -u "$${DEST_FILE}" "$${SRC_FILE}"; \
|
||||
rm "$${TEMP_DEST_FILE}"; \
|
||||
exit 1; \
|
||||
fi; \
|
||||
else \
|
||||
cp "$${SRC_FILE}" "$${DEST_FILE}"; \
|
||||
echo "INFO: \"$${SRC_FILE}\" copied to \"$${DEST_FILE}\""; \
|
||||
echo "[INFO]: \"$${SRC_FILE}\" copied to \"$${DEST_FILE}\""; \
|
||||
fi; \
|
||||
else \
|
||||
echo "WARN: Source file \"$${SRC_FILE}\" does not exist."; \
|
||||
echo "[WARN]: Source file \"$${SRC_FILE}\" does not exist."; \
|
||||
fi
|
||||
endef
|
||||
|
||||
configure:
|
||||
@if [ -d "./builds/$(BUILD)" ]; then \
|
||||
echo "INFO: Configuring build $(BUILD) (./builds/$(BUILD))" && \
|
||||
echo "[INFO]: Configuring build $(BUILD) (./builds/$(BUILD))" && \
|
||||
$(call copy_build_files,$(BUILD),.env); \
|
||||
$(call copy_build_files,$(BUILD),plugins.json); \
|
||||
elif [ -d "./scratch/$(BUILD)" ]; then \
|
||||
echo "INFO: Configuring build $(BUILD) (./scratch/$(BUILD))" && \
|
||||
echo "[INFO]: Configuring build $(BUILD) (./scratch/$(BUILD))" && \
|
||||
$(call copy_build_files,$(BUILD),.env,scratch); \
|
||||
$(call copy_build_files,$(BUILD),plugins.json,scratch); \
|
||||
else \
|
||||
echo "ERROR: Build directory for \"$(BUILD)\" not found"; \
|
||||
echo "[ERROR]: Build directory for \"$(BUILD)\" not found"; \
|
||||
exit 1; \
|
||||
fi
|
||||
|
||||
|
@ -74,7 +74,7 @@ services:
|
||||
context: .
|
||||
dockerfile: ./dockerfiles/Dockerfile.velocity
|
||||
args:
|
||||
VERSION: ${VERSION:-latest}
|
||||
VERSION: ${VELOCITY_VERSION:-latest}
|
||||
image: ${VELOCITY_IMAGE:-localhost/velocity}:${VELOCITY_TAG:-latest}
|
||||
depends_on:
|
||||
- minecraft-jre
|
||||
|
@ -39,7 +39,7 @@ RUN set -eux && \
|
||||
false) \
|
||||
BUILD_TYPE='CRAFTBUKKIT' ;; \
|
||||
*) \
|
||||
echo "ERROR: Invalid value for SPIGOT. Set to 'true' or 'false'"; \
|
||||
echo "[ERROR]: Invalid value for SPIGOT. Set to 'true' or 'false'"; \
|
||||
exit 1 ;; \
|
||||
esac && \
|
||||
# Run BuildTools to build specified version
|
||||
|
@ -36,7 +36,7 @@ RUN set -eux && \
|
||||
false) \
|
||||
JAVA_TYPE='jdk' ;; \
|
||||
*) \
|
||||
echo "ERROR: Invalid value for JAVA_RUNTIME. Set to 'true' or 'false'"; \
|
||||
echo "[ERROR]: Invalid value for JAVA_RUNTIME. Set to 'true' or 'false'"; \
|
||||
exit 1 ;; \
|
||||
esac && \
|
||||
# Install the Temurin version
|
||||
|
@ -40,7 +40,7 @@ RUN set -eux && \
|
||||
| jq -r '.downloads.application.sha256' \
|
||||
)" && \
|
||||
if [ ! "$SHA256" = "$EXPECTED" ]; then \
|
||||
echo "[ERROR] SHA256=\"$SHA256\" expected \"$EXPECTED\""; \
|
||||
echo "[ERROR]: SHA256=\"$SHA256\" expected \"$EXPECTED\""; \
|
||||
exit 1; \
|
||||
fi && \
|
||||
mv /tmp/server.jar /app/server.jar
|
||||
|
@ -25,7 +25,7 @@ RUN set -eux && \
|
||||
SHA1="$(sha1sum server.jar | awk '{print $1}')" && \
|
||||
EXPECTED="$(jq -r .sha1 /tmp/dl.json)"; rm /tmp/dl.json && \
|
||||
if [ ! "$SHA1" = "$EXPECTED" ]; then \
|
||||
echo "[ERROR] SHA1=\"$SHA1\" expected \"$EXPECTED\""; \
|
||||
echo "[ERROR]: SHA1=\"$SHA1\" expected \"$EXPECTED\""; \
|
||||
exit 1; \
|
||||
fi
|
||||
|
||||
|
@ -46,7 +46,7 @@ RUN set -eux && \
|
||||
| jq -r '.downloads.application.sha256' \
|
||||
)" && \
|
||||
if [ ! "$SHA256" = "$EXPECTED" ]; then \
|
||||
echo "[ERROR] SHA256=\"$SHA256\" expected \"$EXPECTED\""; \
|
||||
echo "[ERROR]: SHA256=\"$SHA256\" expected \"$EXPECTED\""; \
|
||||
exit 1; \
|
||||
fi && \
|
||||
mv /tmp/server.jar /app/velocity.jar
|
||||
|
113
entrypoint.sh
113
entrypoint.sh
@ -25,25 +25,72 @@ set_properties() {
|
||||
if ! grep -q "^${KEY}=" "$FILE"; then
|
||||
echo "[WARN]: \"$KEY\" does not exist in $FILE and was not updated"
|
||||
else
|
||||
[ "$DEBUG" = "true" ] && echo "[DEBUG] Updating \"$KEY\" to \"$VALUE\""
|
||||
[ "$DEBUG" = "true" ] && echo "[DEBUG]: Updating \"$KEY\" to \"$VALUE\""
|
||||
sed -i.bak "s/^${KEY}=.*/${KEY}=${VALUE}/" "$FILE"
|
||||
diff --unified=1 "${FILE}.bak" "$FILE"
|
||||
diff --unified=1 "${FILE}.bak" "$FILE" || true
|
||||
rm "${FILE}.bak"
|
||||
fi
|
||||
else
|
||||
if [ "$DEBUG" = "true" ]; then
|
||||
echo "[DEBUG] \"$ENVVAR\" doesn't have the prefix \"$PREFIX\""
|
||||
echo "[DEBUG]: \"$ENVVAR\" doesn't have the prefix \"$PREFIX\""
|
||||
fi
|
||||
fi
|
||||
done < <(env)
|
||||
|
||||
# Show server.properties in DEBUG mode
|
||||
if [ "$DEBUG" = "true" ]; then
|
||||
echo "[DEBUG] Showing ${FILE}:"
|
||||
echo "[DEBUG]: Showing ${FILE}:"
|
||||
cat "$FILE"
|
||||
fi
|
||||
}
|
||||
|
||||
# Set Velocity's forwarding.secret
|
||||
set_forwarding_secret() {
|
||||
local WRITE_FILE
|
||||
local FILE_CONTENT
|
||||
WRITE_FILE=false
|
||||
|
||||
# Check file is not empty
|
||||
if [ -s /app/forwarding.secret ]; then
|
||||
FILE_CONTENT="$(head -c 1025 /app/forwarding.secret)"
|
||||
# Check that FORWARDING_SECRET is blank
|
||||
if [ ! "${#FORWARDING_SECRET}" -gt 0 ]; then
|
||||
# Only the file was set, so FORWARDING_SECRET becomes the file
|
||||
FORWARDING_SECRET="$(head -c 1025 /app/forwarding.secret)"
|
||||
else
|
||||
if [ ! "$FORWARDING_SECRET" = "$FILE_CONTENT" ]; then
|
||||
# You should either bind mount a file in OR set a value
|
||||
echo "[ERROR]: FORWARDING_SECRET is set with an existing file"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
# If the file is zero, we make sure the variable isn't also zero
|
||||
elif [ "${#FORWARDING_SECRET}" -eq 0 ]; then
|
||||
echo "[ERROR]: You must set FORWARDING_SECRET or set a value in the file"
|
||||
exit 1
|
||||
else
|
||||
# File is zero, so we must write the variable out to the file
|
||||
WRITE_FILE=true
|
||||
fi
|
||||
|
||||
# Check length
|
||||
if [ "${#FORWARDING_SECRET}" -lt 32 ]; then
|
||||
echo "[ERROR]: FORWARDING_SECRET needs to be at least 32 characters long"
|
||||
exit 1
|
||||
elif [ "${#FORWARDING_SECRET}" -gt 1024 ]; then
|
||||
echo "[ERROR]: FORWARDING_SECRET is >1024 bytes"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Add secret to file
|
||||
if [ "$WRITE_FILE" = "true" ]; then
|
||||
echo "$FORWARDING_SECRET" > /app/forwarding.secret
|
||||
fi
|
||||
|
||||
# Unset sensitive value
|
||||
unset FORWARDING_SECRET
|
||||
}
|
||||
|
||||
# Check if the minecraft screen is still running
|
||||
# shellcheck disable=SC2317
|
||||
check_screen() {
|
||||
@ -56,6 +103,33 @@ check_screen() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Find Java PID, strace it, and wait for it to exit
|
||||
wait_on_java() {
|
||||
local JAVA_PID
|
||||
local JAVA_EXIT
|
||||
|
||||
# Debug mode
|
||||
[ "$DEBUG" = "true" ] && ps aux
|
||||
|
||||
# Capture PID and test
|
||||
JAVA_PID="$(pgrep java)"
|
||||
if ! kill -0 "$SCREEN_PID" 2>/dev/null; then
|
||||
echo "[ERROR]: Cannot find running Java process (PID: \"$JAVA_PID\")"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# strace Java PID and get return code
|
||||
JAVA_EXIT="$(strace -e trace=exit -p "$JAVA_PID" 2>&1 \
|
||||
| grep -oP '^\+\+\+ exited with \K[0-9]+')"
|
||||
|
||||
# Delay if Java exits non-zero
|
||||
if [ ! "$JAVA_EXIT" = "0" ]; then
|
||||
echo "[ERROR]: Java exited with non-zero status"
|
||||
sleep "${EXIT_DELAY:-5}"
|
||||
exit "$JAVA_EXIT"
|
||||
fi
|
||||
}
|
||||
|
||||
# Find screen PID, strace it, and wait for it to exit
|
||||
wait_on_screen() {
|
||||
local SCREEN_PID
|
||||
@ -82,11 +156,23 @@ wait_on_screen() {
|
||||
tail -f screenlog.0 &
|
||||
TAIL_PID="$!"
|
||||
|
||||
# Debug mode
|
||||
[ "$DEBUG" = "true" ] && ps aux
|
||||
|
||||
# Wait for screen to exit
|
||||
strace -e exit -e signal=none -p "$SCREEN_PID" 2>/dev/null &
|
||||
STRACE_PID="$!"
|
||||
[ "$DEBUG" = "true" ] && ps aux
|
||||
|
||||
# Wait on Java PID first
|
||||
wait_on_java
|
||||
|
||||
# Wait if screen is somehow still running
|
||||
wait "$STRACE_PID"
|
||||
|
||||
# Kill tail PID
|
||||
if kill -0 "$TAIL_PID" 2>/dev/null; then
|
||||
kill "$TAIL_PID"
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to stop the server gracefully
|
||||
@ -107,13 +193,13 @@ stop_server() {
|
||||
# Check only this script is running (PID 1) and pgrep (2 PIDs total)
|
||||
PGREP_OUTPUT="$(pgrep .)"
|
||||
if ! [ "$(echo "$PGREP_OUTPUT" | wc -l)" -eq 2 ]; then
|
||||
echo "[WARN] Some processes might not have exited:"
|
||||
echo "[WARN]: Some processes might not have exited:"
|
||||
echo "$PGREP_OUTPUT"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Exit cleanly
|
||||
echo "[INFO] Server stopped gracefully"
|
||||
echo "[INFO]: Server stopped gracefully"
|
||||
exit 0
|
||||
else
|
||||
echo "[ERROR]: Can't find which screen to use"
|
||||
@ -136,8 +222,12 @@ minecraft_server() {
|
||||
# Set up a SIGTERM signal trap to stop the server
|
||||
trap 'stop_server minecraft' SIGTERM
|
||||
|
||||
# temp
|
||||
ls -al /app
|
||||
ls -al /app/config
|
||||
|
||||
# Run server in screen (without attaching)
|
||||
echo "[INFO] Starting Minecraft server"
|
||||
echo "[INFO]: Starting Minecraft server"
|
||||
/usr/bin/screen -dmS minecraft -L \
|
||||
bash -c "/usr/bin/java $JVM_OPTS -jar server.jar --nogui"
|
||||
|
||||
@ -151,11 +241,14 @@ velocity_server() {
|
||||
# Settings
|
||||
JVM_OPTS="${JVM_OPTS:--Xms1G -Xmx2G}"
|
||||
|
||||
# Ensure there is a forwarding.secret
|
||||
set_forwarding_secret
|
||||
|
||||
# Set up a SIGTERM signal trap to stop the server
|
||||
trap 'stop_server velocity' SIGTERM
|
||||
|
||||
# Start server
|
||||
echo "[INFO] Starting Velocity server"
|
||||
echo "[INFO]: Starting Velocity server"
|
||||
/usr/bin/screen -dmS velocity -L \
|
||||
bash -c "
|
||||
/usr/bin/java $JVM_OPTS -XX:+UseG1GC -XX:G1HeapRegionSize=4M \
|
||||
@ -170,7 +263,7 @@ velocity_server() {
|
||||
# Enable debug mode
|
||||
DEBUG="${DEBUG:-false}"
|
||||
if [ "$DEBUG" = "true" ]; then
|
||||
echo "[DEBUG] Running entrypoint script at $(which entrypoint.sh)"
|
||||
echo "[DEBUG]: Running entrypoint script at $(which entrypoint.sh)"
|
||||
sleep 0.2
|
||||
set -ux
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user