Files
minecraft-docker/scripts/start-server.sh
T
2026-09-06 12:05:08 -05:00

44 lines
1.2 KiB
Bash

#!/bin/bash
# initialize required files for an empty volume
# server.jar
if ! test -f /minecraft_data/server.jar; then
if [ -z "$SERVER_JAR_DOWNLOAD_URL" ]; then
echo "ERROR: SERVER_JAR_DOWNLOAD_URL not set for initial volume creation"
exit 1
fi
wget --no-verbose -O /minecraft_data/server.jar "${SERVER_JAR_DOWNLOAD_URL}"
fi
# server.properties
if ! test -f /minecraft_data/server.properties; then
if [ -z "$MCRCON_PASS" ]; then
echo "ERROR: MCRCON_PASS not set for initial volume creation"
exit 1
fi
cat /defaults/server.properties | sed "s/<password_will_auto_populate>/${MCRCON_PASS}/" | tee /minecraft_data/server.properties
fi
# eula.txt
if ! test -f /minecraft_data/eula.txt; then
cp /defaults/eula.txt /minecraft_data/eula.txt
fi
export MCRCON_PASS=$(grep "^rcon.password=" /minecraft_data/server.properties | cut -d '=' -f 2- | head -n 1)
# shutdown process
function shutdown {
echo "stopping Minecraft server..."
/usr/bin/wircon.pyz -H localhost -p ${MCRCON_PASS} -E /usr/bin/restart.py
wait $SERVER_PID
}
trap shutdown SIGTERM SIGINT
java -jar /minecraft_data/server.jar --nogui &
SERVER_PID=$!
wait $SERVER_PID