2024-01-25 23:12:09 +01:00
|
|
|
#!/usr/sbin/env bash
|
|
|
|
# Disables warning about echo not expanding escape sequences
|
|
|
|
# shellcheck disable=SC2028
|
|
|
|
|
2024-01-27 17:43:29 +01:00
|
|
|
# Used for internal errors
|
|
|
|
function internal_error() {
|
|
|
|
echo "-> INTERNAL ERROR: ${*}"
|
|
|
|
exit 99
|
|
|
|
}
|
|
|
|
|
|
|
|
# Automatically accepts the End User License Agreement
|
|
|
|
function accept_eula() {
|
|
|
|
echo "eula=true" > /data/eula.txt
|
|
|
|
}
|
|
|
|
|
|
|
|
# Cleans /logs and /crash-reports
|
|
|
|
function clean_logs() {
|
|
|
|
if [ "${MCSD_CLEAN_LOGS}" == "true" ]; then
|
|
|
|
rm -rf "/data/logs" "/data/crash-reports"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Used by trap, shuts the server down
|
|
|
|
function kill_server() {
|
|
|
|
if [ -z "${CHILDPID}" ]; then
|
|
|
|
internal_error "\$CHILDPID is unset"
|
|
|
|
fi
|
2024-01-27 18:07:12 +01:00
|
|
|
export "SHUTDOWN=true"
|
|
|
|
kill -INT "${CHILDPID}"
|
2024-01-27 17:43:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Print the MCSD banner
|
2024-01-25 23:12:09 +01:00
|
|
|
function print_banner() {
|
|
|
|
echo " ____ ____ ____ __"
|
|
|
|
echo " /'\\_/\`\\/\\ _\`\\ /\\ _\`\\ /\\ _\`\\ /\\ \\"
|
|
|
|
echo "/\\ \\ \\ \\/\\_\\\\ \\,\\L\\_\\ __ _ __ __ __ __ _ __\\ \\ \\/\\ \\ ___ ___\\ \\ \\/'\\ __ _ __"
|
|
|
|
echo "\\ \\ \\__\\ \\ \\ \\/_/_\\/_\\__ \\ /'__\`\\/\\\`'__\\/\\ \\/\\ \\ /'__\`\\/\\\`'__\\ \\ \\ \\ \\ / __\`\\ /'___\\ \\ , < /'__\`\\/\\\`'__\\"
|
|
|
|
echo " \\ \\ \\_/\\ \\ \\ \\L\\ \\ /\\ \\L\\ \\/\\ __/\\ \\ \\/ \\ \\ \\_/ |/\\ __/\\ \\ \\/ \\ \\ \\_\\ \\/\\ \\L\\ \\/\\ \\__/\\ \\ \\\\\`\\ /\\ __/\\ \\ \\/"
|
|
|
|
echo " \\ \\_\\\\ \\_\\ \\____/ \\ \`\\____\\ \\____\\\\ \\_\\ \\ \\___/ \\ \\____\\\\ \\_\\ \\ \\____/\\ \\____/\\ \\____\\\\ \\_\\ \\_\\ \\____\\\\ \\_\\"
|
|
|
|
echo " \\/_/ \\/_/\\/___/ \\/_____/\\/____/ \\/_/ \\/__/ \\/____/ \\/_/ \\/___/ \\/___/ \\/____/ \\/_/\\/_/\\/____/ \\/_/"
|
|
|
|
}
|
|
|
|
|
2024-01-27 17:43:29 +01:00
|
|
|
# Initialize MCSD
|
2024-01-25 23:12:09 +01:00
|
|
|
function initialize() {
|
|
|
|
echo ":: Initializing MCSD"
|
2024-01-27 17:43:29 +01:00
|
|
|
# Server arguments
|
|
|
|
if [ ! "${MCSD_ENFORCE_FRESH_CACHES}" == "true" ] && [ ! "${MCSD_ENFORCE_FRESH_CACHES}" == "false" ]; then
|
|
|
|
echo ":: Warning: No/Invalid value supplied to \$MCSD_ENFORCE_FRESH_CACHES, defaulting to false"
|
|
|
|
export "MCSD_ENFORCE_FRESH_CACHES=false"
|
2024-01-25 23:12:09 +01:00
|
|
|
fi
|
2024-01-27 17:43:29 +01:00
|
|
|
if [ ! "${MCSD_FORCE_UPGRADE}" == "true" ] && [ ! "${MCSD_FORCE_UPGRADE}" == "false" ]; then
|
|
|
|
echo ":: Warning: No/Invalid value supplied to \$MCSD_FORCE_UPGRADE, defaulting to true"
|
|
|
|
export "MCSD_FORCE_UPGRADE=true"
|
2024-01-25 23:12:09 +01:00
|
|
|
fi
|
2024-01-27 17:43:29 +01:00
|
|
|
if [ ! "${MCSD_SAFEMODE}" == "true" ] && [ ! "${MCSD_SAFEMODE}" == "false" ]; then
|
|
|
|
echo ":: Warning: No/Invalid value supplied to \$MCSD_SAFEMODE, defaulting to false"
|
|
|
|
export "MCSD_SAFEMODE=false"
|
2024-01-25 23:12:09 +01:00
|
|
|
fi
|
2024-01-27 17:43:29 +01:00
|
|
|
# MCSD functionality
|
2024-01-26 14:37:52 +01:00
|
|
|
if [ ! "${MCSD_CLEAN_LOGS}" == "true" ] && [ ! "${MCSD_CLEAN_LOGS}" == "false" ]; then
|
|
|
|
echo ":: Warning: No/Invalid value supplied to \$MCSD_CLEAN_LOGS, defaulting to false"
|
|
|
|
export "MCSD_CLEAN_LOGS=false"
|
|
|
|
fi
|
2024-01-27 17:43:29 +01:00
|
|
|
# Memory limits
|
2024-01-27 18:27:59 +01:00
|
|
|
if [ -z "${MCSD_MEMORY_MIN}" ]; then
|
2024-01-27 17:43:29 +01:00
|
|
|
echo ":: Error: No memory limit supplied to \$MCSD_MEMORY_MIN"
|
|
|
|
exit 1
|
|
|
|
fi
|
2024-01-27 18:27:59 +01:00
|
|
|
if [ -z "${MCSD_MEMORY_MAX}" ]; then
|
2024-01-27 17:43:29 +01:00
|
|
|
echo ":: Error: No memory limit supplied to \$MCSD_MEMORY_MAX"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
# Java version
|
2024-01-25 23:12:09 +01:00
|
|
|
if [ ! "${MCSD_JAVA_VERSION}" == "17" ] && [ ! "${MCSD_JAVA_VERSION}" == "11" ] && [ ! "${MCSD_JAVA_VERSION}" == "8" ]; then
|
2024-01-26 14:37:52 +01:00
|
|
|
echo ":: Warning: No/Invalid java version supplied to \$MCSD_JAVA_VERSION, defaulting to java version 17"
|
2024-01-25 23:12:09 +01:00
|
|
|
export "MCSD_JAVA_VERSION=17"
|
|
|
|
fi
|
2024-01-27 17:43:29 +01:00
|
|
|
# Java optimization
|
|
|
|
if [ ! "${MCSD_OPTIMIZED_FLAGS}" == "true" ] && [ ! "${MCSD_OPTIMIZED_FLAGS}" == "false" ]; then
|
|
|
|
echo ":: Warning: No/Invalid value supplied to \$MCSD_OPTIMIZED_FLAGS, defaulting to true"
|
|
|
|
export "MCSD_OPTIMIZED_FLAGS=true"
|
|
|
|
fi
|
|
|
|
if [ ! "${MCSD_GARBAGECOLLECTOR}" == "G1GC" ] && [ ! "${MCSD_GARBAGECOLLECTOR}" == "ZGC" ]; then
|
|
|
|
echo ":: Warning: No/Invalid value supplied to \$MCSD_GARBAGECOLLECTOR, defaulting to G1GC"
|
|
|
|
export "MCSD_GARBAGECOLLECTOR=G1GC"
|
|
|
|
fi
|
2024-01-25 23:12:09 +01:00
|
|
|
}
|
|
|
|
|
2024-01-27 17:43:29 +01:00
|
|
|
# Check for directories and files
|
2024-01-25 23:12:09 +01:00
|
|
|
function check() {
|
|
|
|
echo ":: Checking environment"
|
|
|
|
if [ ! -d "/data" ]; then
|
|
|
|
echo ":: Error: Could not locate /data directory"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [ ! -f "/data/server.jar" ]; then
|
|
|
|
echo ":: Error: Could not locate server.jar"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-01-27 17:43:29 +01:00
|
|
|
# Compile server arguments
|
|
|
|
function compile_args() {
|
|
|
|
echo ":: Compiling server arguments"
|
|
|
|
export "ARGS=--nogui"
|
|
|
|
case "${MCSD_ENFORCE_FRESH_CACHES}" in
|
|
|
|
"true")
|
|
|
|
export "ARGS=${ARGS} --eraseCache"
|
|
|
|
;;
|
|
|
|
"false") ;;
|
|
|
|
*)
|
|
|
|
internal_error "\$MCSD_ENFORCE_FRESH_CACHES has invalid value"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
case "${MCSD_FORCE_UPGRADE}" in
|
|
|
|
"true")
|
|
|
|
export "ARGS=${ARGS} --forceUpgrade"
|
|
|
|
;;
|
|
|
|
"false") ;;
|
|
|
|
*)
|
|
|
|
internal_error "\$MCSD_FORCE_UPGRADE has invalid value"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
case "${MCSD_SAFEMODE}" in
|
|
|
|
"true")
|
|
|
|
export "ARGS=${ARGS} --safeMode"
|
|
|
|
;;
|
|
|
|
"false") ;;
|
|
|
|
*)
|
|
|
|
internal_error "\$MCSD_SAFEMODE has invalid value"
|
|
|
|
;;
|
|
|
|
esac
|
2024-01-26 01:12:24 +01:00
|
|
|
}
|
|
|
|
|
2024-01-27 17:43:29 +01:00
|
|
|
# Compile java flags
|
|
|
|
function compile_flags() {
|
|
|
|
echo ":: Compiling java flags"
|
|
|
|
export "FLAGS=-Xms${MCSD_MEMORY_MIN} -Xmx${MCSD_MEMORY_MAX}"
|
|
|
|
case "${MCSD_OPTIMIZED_FLAGS}" in
|
|
|
|
"true")
|
|
|
|
export "FLAGS=${FLAGS} -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions -XX:+AlwaysActAsServerClassMachine -XX:+AlwaysPreTouch -XX:+DisableExplicitGC -XX:+UseNUMA -XX:NmethodSweepActivity=1 -XX:ReservedCodeCacheSize=400M -XX:NonNMethodCodeHeapSize=12M -XX:ProfiledCodeHeapSize=194M -XX:NonProfiledCodeHeapSize=194M -XX:-DontCompileHugeMethods -XX:MaxNodeLimit=240000 -XX:NodeLimitFudgeFactor=8000 -XX:+UseVectorCmov -XX:+PerfDisableSharedMem -XX:+UseFastUnorderedTimeStamps -XX:+UseCriticalJavaThreadPriority -XX:ThreadPriorityPolicy=1 -XX:AllocatePrefetchStyle=3"
|
|
|
|
;;
|
|
|
|
"false") ;;
|
|
|
|
*)
|
|
|
|
internal_error "\$MCSD_OPTIMIZED_FLAGS has invalid value"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
case "${MCSD_GARBAGECOLLECTOR}" in
|
|
|
|
"G1GC")
|
|
|
|
export "FLAGS=${FLAGS} -XX:+UseG1GC -XX:MaxGCPauseMillis=130 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=28 -XX:G1HeapRegionSize=16M -XX:G1ReservePercent=20 -XX:G1MixedGCCountTarget=3 -XX:InitiatingHeapOccupancyPercent=10 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=0 -XX:SurvivorRatio=32 -XX:MaxTenuringThreshold=1 -XX:G1SATBBufferEnqueueingThresholdPercent=30 -XX:G1ConcMarkStepDurationMillis=5 -XX:G1ConcRSHotCardLimit=16 -XX:G1ConcRefinementServiceIntervalMillis=150"
|
|
|
|
;;
|
|
|
|
"ZGC")
|
|
|
|
export "FLAGS=${FLAGS} -XX:+UseZGC -XX:AllocatePrefetchStyle=1 -XX:-ZProactive"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
internal_error "\$MCSD_GARBAGECOLLECTOR has invalid value"
|
|
|
|
;;
|
|
|
|
esac
|
2024-01-26 15:38:08 +01:00
|
|
|
}
|
|
|
|
|
2024-04-20 17:08:06 +02:00
|
|
|
print_banner
|
|
|
|
initialize
|
|
|
|
check
|
|
|
|
accept_eula
|
|
|
|
clean_logs
|
|
|
|
compile_args
|
|
|
|
compile_flags
|
2024-01-25 23:12:09 +01:00
|
|
|
|
2024-04-20 17:08:06 +02:00
|
|
|
echo ":: Starting server"
|
|
|
|
cd /data||exit 69
|
2024-04-20 17:14:51 +02:00
|
|
|
if [ -z "${MCSD_CUSTOM_ARGS}" ]; then
|
|
|
|
exec "/usr/lib/jvm/java-${MCSD_JAVA_VERSION}-openjdk/bin/java" ${FLAGS} -jar "/data/server.jar" ${ARGS}
|
|
|
|
else
|
|
|
|
exec "/usr/lib/jvm/java-${MCSD_JAVA_VERSION}-openjdk/bin/java" ${MCSD_CUSTOM_ARGS}
|
|
|
|
fi
|