Files
MinecraftScripts/ServerStart.sh.template
2021-05-06 18:00:11 +02:00

32 lines
1.6 KiB
Plaintext

while true; do
# prevent the server from being stopped again immediately
date +%s > /home/minecraft/scripts/lp_stamp
# run the server itself
# replace the jolokia agent and the forge jar with your versions
java -jar -Xms20G -Xmx20G -javaagent:jolokia-jvm-1.6.2-agent.jar\
-XX:+UseG1GC -XX:+UnlockExperimentalVMOptions -XX:MaxGCPauseMillis=100\
-XX:+DisableExplicitGC -XX:TargetSurvivorRatio=90 -XX:G1NewSizePercent=50\
-XX:G1MaxNewSizePercent=80 -XX:G1MixedGCLiveThresholdPercent=50\
-XX:G1ReservePercent=20 -XX:ConcGCThreads=2 -XX:ParallelGCThreads=4\
-XX:InitiatingHeapOccupancyPercent=25\
-XX:+AlwaysPreTouch -Xloggc:gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps\
-XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=1M forge-1.16.5-36.0.1.jar nogui
echo "Server closed"
if (( $(cat /home/minecraft/scripts/lp_shutdown) > 0 )); then
echo "Server was empty for 14 days, waiting for connection..."
echo "0" > /home/minecraft/scripts/lp_shutdown
mcconn=0
until [ $mcconn -ne 0 ]; do
mcconn=$(nc -l 25500 | cat -v | grep -czP '(\^X\^@M-r\^E\^Q)([\w\.]+)(\^@FML2\^@cM-\^\\\^B\n\^@\^H)([\w\.]+)')
if [ $mcconn -eq 0 ]; then
echo "Something connected, but it doesn't look like a minecraft connection"
else
echo "Someone tried to connect to the minecraft server, starting..."
fi
done
else
echo "Restarting server in 5 seconds..."
sleep 5
fi
done