2017-11-01 05:42:44 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2019-05-26 16:59:39 +00:00
|
|
|
. /start-utils
|
|
|
|
|
2019-09-08 22:22:02 +00:00
|
|
|
if [ -n "$OPS" ]; then
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Setting/adding ops"
|
2019-09-08 22:22:02 +00:00
|
|
|
rm -rf ops.txt.converted
|
|
|
|
echo $OPS | awk -v RS=, '{print}' > ops.txt
|
2017-11-01 05:42:44 +00:00
|
|
|
fi
|
|
|
|
|
2019-09-22 21:48:59 +00:00
|
|
|
if [ -n "$WHITELIST" ]; then
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Setting whitelist"
|
2019-09-22 21:48:59 +00:00
|
|
|
rm -rf white-list.txt.converted
|
|
|
|
echo $WHITELIST | awk -v RS=, '{print}' > white-list.txt
|
2017-11-01 05:42:44 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$ICON" -a ! -e server-icon.png ]; then
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Using server icon from $ICON..."
|
2017-11-01 05:42:44 +00:00
|
|
|
# Not sure what it is yet...call it "img"
|
2018-06-26 00:13:47 +00:00
|
|
|
curl -sSL -o /tmp/icon.img $ICON
|
2017-11-01 05:42:44 +00:00
|
|
|
specs=$(identify /tmp/icon.img | awk '{print $2,$3}')
|
|
|
|
if [ "$specs" = "PNG 64x64" ]; then
|
|
|
|
mv /tmp/icon.img /data/server-icon.png
|
|
|
|
else
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Converting image to 64x64 PNG..."
|
2017-11-01 05:42:44 +00:00
|
|
|
convert /tmp/icon.img -resize 64x64! /data/server-icon.png
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2020-04-05 22:32:26 +00:00
|
|
|
if [ ${TYPE} != "SPIGOT" ]; then
|
2020-03-20 21:29:52 +00:00
|
|
|
# Set up log configuration
|
|
|
|
LOGFILE="/data/log4j2.xml"
|
|
|
|
if [ ! -e "$LOGFILE" ]; then
|
|
|
|
log "Creating log4j2.xml in ${LOGFILE}"
|
|
|
|
cp /tmp/log4j2.xml "$LOGFILE"
|
|
|
|
else
|
|
|
|
log "log4j2.xml already created, skipping"
|
|
|
|
fi
|
|
|
|
JVM_OPTS="-Dlog4j.configurationFile=/data/log4j2.xml ${JVM_OPTS}"
|
2020-04-05 22:32:26 +00:00
|
|
|
fi
|
2020-03-20 21:29:52 +00:00
|
|
|
|
2017-11-01 05:42:44 +00:00
|
|
|
# Make sure files exist and are valid JSON (for pre-1.12 to 1.12 upgrades)
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Checking for JSON files."
|
2019-03-11 02:50:42 +00:00
|
|
|
JSON_FILES=$(find . -maxdepth 1 -name '*.json')
|
2018-10-14 17:47:39 +00:00
|
|
|
for j in $JSON_FILES; do
|
2020-04-11 13:43:17 +00:00
|
|
|
if [[ $(cat "$j" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') == "" ]]; then
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Fixing JSON $j"
|
2018-10-14 17:47:39 +00:00
|
|
|
echo '[]' > $j
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2017-11-01 05:42:44 +00:00
|
|
|
|
|
|
|
# If any modules have been provided, copy them over
|
|
|
|
mkdir -p /data/mods
|
2018-12-15 07:29:43 +00:00
|
|
|
if [ -d /mods ]; then
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Copying any mods over..."
|
2019-04-27 18:47:26 +00:00
|
|
|
rsync -a --out-format="update:%f:Last Modified %M" --prune-empty-dirs --update /mods /data
|
2018-12-15 07:29:43 +00:00
|
|
|
fi
|
|
|
|
|
2017-11-01 05:42:44 +00:00
|
|
|
[ -d /data/config ] || mkdir /data/config
|
|
|
|
for c in /config/*
|
|
|
|
do
|
|
|
|
if [ -f "$c" ]; then
|
2020-04-11 13:43:17 +00:00
|
|
|
log Copying configuration $(basename "$c")
|
2017-11-01 05:42:44 +00:00
|
|
|
cp -rf "$c" /data/config
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2020-04-04 15:13:51 +00:00
|
|
|
case ${TYPE} in
|
|
|
|
SPIGOT|BUKKIT|PAPER)
|
|
|
|
mkdir -p /data/plugins
|
|
|
|
if [ -d /plugins ]; then
|
|
|
|
log "Copying plugins over..."
|
|
|
|
# Copy plugins over using rsync to allow deeply nested updates of plugins
|
|
|
|
# only updates files if the source file is newer and print updated files
|
|
|
|
rsync -a --out-format="update:%f:Last Modified %M" --prune-empty-dirs --update /plugins /data
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
2017-11-01 05:42:44 +00:00
|
|
|
|
|
|
|
EXTRA_ARGS=""
|
|
|
|
# Optional disable console
|
|
|
|
if [[ ${CONSOLE} = false || ${CONSOLE} = FALSE ]]; then
|
|
|
|
EXTRA_ARGS+="--noconsole"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Optional disable GUI for headless servers
|
|
|
|
if [[ ${GUI} = false || ${GUI} = FALSE ]]; then
|
|
|
|
EXTRA_ARGS="${EXTRA_ARGS} nogui"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# put these prior JVM_OPTS at the end to give any memory settings there higher precedence
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Setting initial memory to ${INIT_MEMORY:=${MEMORY}} and max to ${MAX_MEMORY:=${MEMORY}}"
|
2017-11-01 05:42:44 +00:00
|
|
|
|
2019-01-14 04:22:27 +00:00
|
|
|
expandedDOpts=
|
|
|
|
if [ -n "$JVM_DD_OPTS" ]; then
|
|
|
|
for dopt in $JVM_DD_OPTS
|
|
|
|
do
|
|
|
|
expandedDOpts="${expandedDOpts} -D${dopt/:/=}"
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2020-04-03 17:32:46 +00:00
|
|
|
if isTrue ${ENABLE_JMX}; then
|
|
|
|
: ${JMX_HOST:=0.0.0.0}
|
|
|
|
: ${JMX_PORT:=7091}
|
|
|
|
JVM_OPTS="${JVM_OPTS}
|
|
|
|
-Dcom.sun.management.jmxremote.local.only=false
|
|
|
|
-Dcom.sun.management.jmxremote.port=${JMX_PORT}
|
|
|
|
-Dcom.sun.management.jmxremote.rmi.port=${JMX_PORT}
|
|
|
|
-Dcom.sun.management.jmxremote.authenticate=false
|
|
|
|
-Dcom.sun.management.jmxremote.ssl=false
|
|
|
|
-Dcom.sun.management.jmxremote.host=${JMX_HOST}
|
|
|
|
-Djava.rmi.server.hostname=${JMX_HOST}"
|
|
|
|
|
|
|
|
log "JMX is enabled. Make sure you have port forwarding for ${JMX_PORT}"
|
|
|
|
fi
|
|
|
|
|
2020-04-11 15:41:20 +00:00
|
|
|
if isTrue "${USE_AIKAR_FLAGS}"; then
|
|
|
|
# From https://mcflags.emc.gs/
|
|
|
|
|
|
|
|
if (( $(normalizeMemSize "${MAX_MEMORY}") >= $(normalizeMemSize 12g) )); then
|
|
|
|
log "Using Aikar's >12GB flags"
|
|
|
|
G1NewSizePercent=40
|
|
|
|
G1MaxNewSizePercent=50
|
|
|
|
G1HeapRegionSize=16M
|
|
|
|
G1ReservePercent=15
|
|
|
|
InitiatingHeapOccupancyPercent=20
|
|
|
|
else
|
|
|
|
log "Using Aikar's flags"
|
|
|
|
G1NewSizePercent=30
|
|
|
|
G1MaxNewSizePercent=40
|
|
|
|
G1HeapRegionSize=8M
|
|
|
|
G1ReservePercent=20
|
|
|
|
InitiatingHeapOccupancyPercent=15
|
|
|
|
fi
|
|
|
|
|
|
|
|
JVM_XX_OPTS="${JVM_XX_OPTS}
|
2020-04-11 13:43:17 +00:00
|
|
|
-XX:+UseG1GC -XX:+ParallelRefProcEnabled
|
|
|
|
-XX:MaxGCPauseMillis=200
|
|
|
|
-XX:+UnlockExperimentalVMOptions
|
|
|
|
-XX:+DisableExplicitGC
|
|
|
|
-XX:-OmitStackTraceInFastThrow
|
|
|
|
-XX:+AlwaysPreTouch
|
2020-04-11 15:41:20 +00:00
|
|
|
-XX:G1NewSizePercent=${G1NewSizePercent}
|
|
|
|
-XX:G1MaxNewSizePercent=${G1MaxNewSizePercent}
|
|
|
|
-XX:G1HeapRegionSize=${G1HeapRegionSize}
|
|
|
|
-XX:G1ReservePercent=${G1ReservePercent}
|
2020-04-11 13:43:17 +00:00
|
|
|
-XX:G1HeapWastePercent=5
|
|
|
|
-XX:G1MixedGCCountTarget=8
|
2020-04-11 15:41:20 +00:00
|
|
|
-XX:InitiatingHeapOccupancyPercent=${InitiatingHeapOccupancyPercent}
|
2020-04-11 13:43:17 +00:00
|
|
|
-XX:G1MixedGCLiveThresholdPercent=90
|
|
|
|
-XX:G1RSetUpdatingPauseTimePercent=5
|
|
|
|
-XX:SurvivorRatio=32
|
|
|
|
-XX:MaxTenuringThreshold=1
|
|
|
|
-Dusing.aikars.flags=true
|
|
|
|
-Daikars.new.flags=true
|
|
|
|
"
|
|
|
|
fi
|
|
|
|
|
2020-04-11 15:41:20 +00:00
|
|
|
if isTrue "${USE_LARGE_PAGES}"; then
|
|
|
|
JVM_XX_OPTS="${JVM_XX_OPTS}
|
|
|
|
-XX:+UseLargePagesInMetaspace
|
|
|
|
"
|
|
|
|
fi
|
|
|
|
|
2019-01-25 00:39:26 +00:00
|
|
|
mcServerRunnerArgs="--stop-duration 60s"
|
|
|
|
|
2017-11-01 05:42:44 +00:00
|
|
|
if [[ ${TYPE} == "FEED-THE-BEAST" ]]; then
|
2020-04-01 23:50:07 +00:00
|
|
|
mcServerRunnerArgs="${mcServerRunnerArgs} --shell bash"
|
|
|
|
|
2019-06-08 21:47:28 +00:00
|
|
|
if [ ! -e "${FTB_DIR}/ops.json" -a -e /data/ops.txt ]; then
|
2018-02-06 20:21:23 +00:00
|
|
|
cp -f /data/ops.txt ${FTB_DIR}/
|
|
|
|
fi
|
|
|
|
|
2019-06-08 21:47:28 +00:00
|
|
|
if [ ! -e "${FTB_DIR}/whitelist.json" -a -e /data/white-list.txt ]; then
|
2018-03-05 01:01:31 +00:00
|
|
|
cp -f /data/white-list.txt ${FTB_DIR}/
|
2018-02-06 20:21:23 +00:00
|
|
|
fi
|
|
|
|
|
2019-06-08 21:47:28 +00:00
|
|
|
cp -f /data/eula.txt "${FTB_DIR}/"
|
2018-02-06 20:21:23 +00:00
|
|
|
|
2019-06-08 21:47:28 +00:00
|
|
|
cat > "${FTB_DIR}/settings-local.sh" <<EOF
|
2018-07-13 21:35:56 +00:00
|
|
|
export MIN_RAM="${INIT_MEMORY}"
|
|
|
|
export MAX_RAM="${MAX_MEMORY}"
|
2019-10-14 16:24:26 +00:00
|
|
|
export JAVA_PARAMETERS="${JVM_XX_OPTS} -Xms${INIT_MEMORY} ${JVM_OPTS} $expandedDOpts"
|
2018-07-13 21:35:56 +00:00
|
|
|
EOF
|
|
|
|
|
2019-01-26 22:35:00 +00:00
|
|
|
# patch CurseForge cfg file, if present
|
2019-06-08 21:47:28 +00:00
|
|
|
if [ -f "${FTB_DIR}/settings.cfg" ]; then
|
2019-08-02 16:29:22 +00:00
|
|
|
sed -i "s/MAX_RAM=[^;]*/MAX_RAM=${MAX_MEMORY}/" "${FTB_DIR}/settings.cfg"
|
2019-01-26 22:35:00 +00:00
|
|
|
fi
|
|
|
|
|
2019-06-08 21:47:28 +00:00
|
|
|
cd "${FTB_DIR}"
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Running FTB ${FTB_SERVER_START} in ${FTB_DIR} ..."
|
2019-05-26 16:59:39 +00:00
|
|
|
if isTrue ${DEBUG_EXEC}; then
|
|
|
|
set -x
|
|
|
|
fi
|
2019-06-08 21:47:28 +00:00
|
|
|
exec mc-server-runner ${mcServerRunnerArgs} "${FTB_SERVER_START}"
|
2017-11-01 05:42:44 +00:00
|
|
|
else
|
2018-07-13 21:35:56 +00:00
|
|
|
# If we have a bootstrap.txt file... feed that in to the server stdin
|
|
|
|
if [ -f /data/bootstrap.txt ]; then
|
|
|
|
bootstrapArgs="--bootstrap /data/bootstrap.txt"
|
|
|
|
fi
|
2019-05-13 23:21:38 +00:00
|
|
|
|
2020-03-06 15:52:17 +00:00
|
|
|
log "Starting the Minecraft server..."
|
2018-07-13 21:35:56 +00:00
|
|
|
JVM_OPTS="-Xms${INIT_MEMORY} -Xmx${MAX_MEMORY} ${JVM_OPTS}"
|
2019-05-26 16:59:39 +00:00
|
|
|
if isTrue ${DEBUG_EXEC}; then
|
|
|
|
set -x
|
|
|
|
fi
|
2019-01-25 00:39:26 +00:00
|
|
|
exec mc-server-runner ${bootstrapArgs} ${mcServerRunnerArgs} java $JVM_XX_OPTS $JVM_OPTS $expandedDOpts -jar $SERVER "$@" $EXTRA_ARGS
|
2017-11-01 05:42:44 +00:00
|
|
|
fi
|