From 21ee5e2401a08d03ca3d4484893c50b7c43de1ae Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Sun, 19 Jul 2020 12:22:15 -0500 Subject: [PATCH 1/6] Changed handling of unrecognized VERSION and detect absent server in meta json For #590 --- start-configuration | 5 +---- start-deployVanilla | 3 +++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/start-configuration b/start-configuration index deb6e792..efb837aa 100644 --- a/start-configuration +++ b/start-configuration @@ -71,11 +71,8 @@ case "X$VERSION" in XSNAPSHOT|Xsnapshot) VANILLA_VERSION=$(curl -fsSL $VERSIONS_JSON | jq -r '.latest.snapshot') ;; - X[1-9]*) - VANILLA_VERSION=$VERSION - ;; *) - VANILLA_VERSION=$(curl -fsSL $VERSIONS_JSON | jq -r '.latest.release') + VANILLA_VERSION=$VERSION ;; esac export VANILLA_VERSION diff --git a/start-deployVanilla b/start-deployVanilla index 59283b15..c7c9d05f 100644 --- a/start-deployVanilla +++ b/start-deployVanilla @@ -26,6 +26,9 @@ if [ ! -e $SERVER ] || [ -n "$FORCE_REDOWNLOAD" ]; then if [ $result != 0 ]; then log "ERROR failed to obtain version manifest from $versionManifestUrl ($result)" exit 1 + elif [ $serverDownloadUrl = null ]; then + log "ERROR version $VANILLA_VERSION does not provide a server download" + exit 1 fi debug "Downloading server from $serverDownloadUrl" From beaccbcf3b4d8bc59d79c6670c6c25d35772c004 Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Sun, 19 Jul 2020 15:01:19 -0500 Subject: [PATCH 2/6] Added option to set USE_MODPACK_START_SCRIPT=false for CF modpacks (#591) --- README.md | 4 ++++ start-deployFTB | 37 +++++++++++++++++++++++++++++++++---- start-minecraftFinalSetup | 11 +++++++++-- start-utils | 4 ++++ 4 files changed, 50 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0d5e7bcb..726d1297 100644 --- a/README.md +++ b/README.md @@ -513,6 +513,10 @@ The following example uses `/modpacks` as the container path as the pre-download -e CF_SERVER_MOD=/modpacks/SkyFactory_4_Server_4.1.0.zip \ -p 25565:25565 -e EULA=TRUE --name mc itzg/minecraft-server +#### Buggy start scripts + +Some modpacks have buggy or overly complex start scripts. You can avoid using the bundled start script and use this image's standard server-starting logic by adding `-e USE_MODPACK_START_SCRIPT=false`. + ### Fixing "unable to launch forgemodloader" If your server's modpack fails to load with an error [like this](https://support.feed-the-beast.com/t/cant-start-crashlanding-server-unable-to-launch-forgemodloader/6028/2): diff --git a/start-deployFTB b/start-deployFTB index 5e2b5c4f..66d8559b 100644 --- a/start-deployFTB +++ b/start-deployFTB @@ -1,5 +1,7 @@ #!/bin/bash +set -e + . ${SCRIPTS:-/}start-utils export FTB_BASE_DIR=/data/FeedTheBeast @@ -9,11 +11,38 @@ export TYPE=FEED-THE-BEAST FTB_SERVER_MOD=${FTB_SERVER_MOD:-$CF_SERVER_MOD} log "Looking for Feed-The-Beast / CurseForge server modpack." -if [[ -z $FTB_SERVER_MOD ]]; then - log "Environment variable FTB_SERVER_MOD not set." - log "Set FTB_SERVER_MOD to the file name of the FTB server modpack." - log "(And place the modpack in the /data directory.)" +requireVar FTB_SERVER_MOD + +if ! isTrue ${USE_MODPACK_START_SCRIPT:-true}; then + if ! [ -f ${FTB_SERVER_MOD} ]; then + log "ERROR unable to find requested modpack file ${FTB_SERVER_MOD}" exit 2 + fi + + log "Unpacking FTB server modpack ${FTB_SERVER_MOD} ..." + mkdir -p ${FTB_BASE_DIR} + unzip -o ${FTB_SERVER_MOD} -d ${FTB_BASE_DIR} | awk '{printf "."} END {print ""}' + + forgeInstallerJar=$(find ${FTB_BASE_DIR} -name "forge*installer.jar") + if [[ -z "${forgeInstallerJar}" ]]; then + log "ERROR Unable to find forge installer in modpack." + log " Make sure you downloaded the server files." + exit 2 + fi + + log "Installing forge server" + (cd $(dirname "${forgeInstallerJar}"); java -jar $(basename ${forgeInstallerJar}) --installServer) | awk '{printf "."} END {print ""}' + + export SERVER=$(find ${FTB_BASE_DIR} -not -name "forge*installer.jar" -name "forge*.jar") + if [[ -z "${SERVER}" || ! -f "${SERVER}" ]]; then + log "ERROR unable to locate installed forge server jar" + isDebugging && find ${FTB_BASE_DIR} -name "forge*.jar" + exit 2 + fi + + export FTB_DIR=$(dirname "${SERVER}") + + exec ${SCRIPTS:-/}start-finalSetupWorld $@ fi entryScriptExpr=" diff --git a/start-minecraftFinalSetup b/start-minecraftFinalSetup index 5b8af846..3fd2a21c 100644 --- a/start-minecraftFinalSetup +++ b/start-minecraftFinalSetup @@ -158,15 +158,23 @@ if isTrue "${DEBUG_MEMORY}"; then free -m fi +JVM_OPTS="-Xms${INIT_MEMORY} -Xmx${MAX_MEMORY} ${JVM_OPTS}" + mcServerRunnerArgs="--stop-duration 60s" if [[ ${TYPE} == "CURSE_INSTANCE" ]]; then - JVM_OPTS="-Xms${INIT_MEMORY} -Xmx${MAX_MEMORY} ${JVM_OPTS}" if isTrue ${DEBUG_EXEC}; then set -x fi exec mc-server-runner ${mcServerRunnerArgs} \ --cf-instance-file "${CURSE_INSTANCE_JSON}" \ java $JVM_XX_OPTS $JVM_OPTS $expandedDOpts -jar _SERVERJAR_ "$@" $EXTRA_ARGS +elif [[ ${TYPE} == "FEED-THE-BEAST" && "${SERVER}" ]]; then + cd "${FTB_DIR}" + log "Starting CurseForge server in ${FTB_DIR}..." + if isTrue ${DEBUG_EXEC}; then + set -x + fi + exec mc-server-runner ${bootstrapArgs} ${mcServerRunnerArgs} java $JVM_XX_OPTS $JVM_OPTS $expandedDOpts -jar $(basename "${SERVER}") "$@" $EXTRA_ARGS elif [[ ${TYPE} == "FEED-THE-BEAST" ]]; then mcServerRunnerArgs="${mcServerRunnerArgs} --shell bash" @@ -205,7 +213,6 @@ else fi log "Starting the Minecraft server..." - JVM_OPTS="-Xms${INIT_MEMORY} -Xmx${MAX_MEMORY} ${JVM_OPTS}" if isTrue ${DEBUG_EXEC}; then set -x fi diff --git a/start-utils b/start-utils index 0c6fd763..ffbdec29 100644 --- a/start-utils +++ b/start-utils @@ -108,4 +108,8 @@ requireVar() { log "ERROR: $1 is required to be set" exit 1 fi + if [ -z "${!1}" ]; then + log "ERROR: $1 is required to be set" + exit 1 + fi } From 06cffd9e15b987acc9d534d0470e0f59fde6420a Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Sun, 19 Jul 2020 16:29:41 -0500 Subject: [PATCH 3/6] Ensured eula and other files brought over when not using CF start script (#591) --- start-minecraftFinalSetup | 50 ++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/start-minecraftFinalSetup b/start-minecraftFinalSetup index 3fd2a21c..21b933cf 100644 --- a/start-minecraftFinalSetup +++ b/start-minecraftFinalSetup @@ -160,6 +160,19 @@ fi JVM_OPTS="-Xms${INIT_MEMORY} -Xmx${MAX_MEMORY} ${JVM_OPTS}" +function copyFilesForCurseForge() { + # copy player modification files unconditionally since their + # processing into json is additive anyway + [ -f /data/ops.txt ] && cp -f /data/ops.txt ${FTB_DIR}/ + [ -f /data/white-list.txt ] && cp -f /data/white-list.txt ${FTB_DIR}/ + + if [ ! -e "${FTB_DIR}/server-icon.png" -a -e /data/server-icon.png ]; then + cp -f /data/server-icon.png ${FTB_DIR}/ + fi + + cp -f /data/eula.txt "${FTB_DIR}/" +} + mcServerRunnerArgs="--stop-duration 60s" if [[ ${TYPE} == "CURSE_INSTANCE" ]]; then if isTrue ${DEBUG_EXEC}; then @@ -169,6 +182,8 @@ if [[ ${TYPE} == "CURSE_INSTANCE" ]]; then --cf-instance-file "${CURSE_INSTANCE_JSON}" \ java $JVM_XX_OPTS $JVM_OPTS $expandedDOpts -jar _SERVERJAR_ "$@" $EXTRA_ARGS elif [[ ${TYPE} == "FEED-THE-BEAST" && "${SERVER}" ]]; then + copyFilesForCurseForge + cd "${FTB_DIR}" log "Starting CurseForge server in ${FTB_DIR}..." if isTrue ${DEBUG_EXEC}; then @@ -176,36 +191,27 @@ elif [[ ${TYPE} == "FEED-THE-BEAST" && "${SERVER}" ]]; then fi exec mc-server-runner ${bootstrapArgs} ${mcServerRunnerArgs} java $JVM_XX_OPTS $JVM_OPTS $expandedDOpts -jar $(basename "${SERVER}") "$@" $EXTRA_ARGS elif [[ ${TYPE} == "FEED-THE-BEAST" ]]; then - mcServerRunnerArgs="${mcServerRunnerArgs} --shell bash" + mcServerRunnerArgs="${mcServerRunnerArgs} --shell bash" - # copy player modification files unconditionally since their - # processing into json is additive anyway - [ -f /data/ops.txt ] && cp -f /data/ops.txt ${FTB_DIR}/ - [ -f /data/white-list.txt ] && cp -f /data/white-list.txt ${FTB_DIR}/ + copyFilesForCurseForge - if [ ! -e "${FTB_DIR}/server-icon.png" -a -e /data/server-icon.png ]; then - cp -f /data/server-icon.png ${FTB_DIR}/ - fi - - cp -f /data/eula.txt "${FTB_DIR}/" - - cat > "${FTB_DIR}/settings-local.sh" < "${FTB_DIR}/settings-local.sh" < Date: Sun, 19 Jul 2020 18:10:16 -0500 Subject: [PATCH 4/6] Added support for upgrading with USE_MODPACK_START_SCRIPT=false --- start-deployFTB | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/start-deployFTB b/start-deployFTB index 66d8559b..eb455651 100644 --- a/start-deployFTB +++ b/start-deployFTB @@ -19,19 +19,38 @@ if ! isTrue ${USE_MODPACK_START_SCRIPT:-true}; then exit 2 fi - log "Unpacking FTB server modpack ${FTB_SERVER_MOD} ..." - mkdir -p ${FTB_BASE_DIR} - unzip -o ${FTB_SERVER_MOD} -d ${FTB_BASE_DIR} | awk '{printf "."} END {print ""}' + needsInstall=true + installMarker=/data/.curseforge-installed + if [ -f $installMarker ]; then + if [ "$(cat $installMarker)" != "${FTB_SERVER_MOD}" ]; then + log "Upgrading modpack" - forgeInstallerJar=$(find ${FTB_BASE_DIR} -name "forge*installer.jar") - if [[ -z "${forgeInstallerJar}" ]]; then - log "ERROR Unable to find forge installer in modpack." - log " Make sure you downloaded the server files." - exit 2 + serverJar=$(find ${FTB_BASE_DIR} -not -name "forge*installer.jar" -name "forge*.jar") + if [[ "${serverJar}" ]]; then + rm -rf $(dirname "${serverJar}")/{mods,*.jar,libraries,resources,scripts} + fi + else + needsInstall=false + fi fi - log "Installing forge server" - (cd $(dirname "${forgeInstallerJar}"); java -jar $(basename ${forgeInstallerJar}) --installServer) | awk '{printf "."} END {print ""}' + if $needsInstall; then + log "Unpacking FTB server modpack ${FTB_SERVER_MOD} ..." + mkdir -p ${FTB_BASE_DIR} + unzip -o ${FTB_SERVER_MOD} -d ${FTB_BASE_DIR} | awk '{printf "."} END {print ""}' + + forgeInstallerJar=$(find ${FTB_BASE_DIR} -name "forge*installer.jar") + if [[ -z "${forgeInstallerJar}" ]]; then + log "ERROR Unable to find forge installer in modpack." + log " Make sure you downloaded the server files." + exit 2 + fi + + log "Installing forge server" + (cd $(dirname "${forgeInstallerJar}"); java -jar $(basename ${forgeInstallerJar}) --installServer) | awk '{printf "."} END {print ""}' + + echo "${FTB_SERVER_MOD}" > $installMarker + fi export SERVER=$(find ${FTB_BASE_DIR} -not -name "forge*installer.jar" -name "forge*.jar") if [[ -z "${SERVER}" || ! -f "${SERVER}" ]]; then From 82b840141461e995689223bf05bf18aa33894be6 Mon Sep 17 00:00:00 2001 From: nrgbistro <35301702+nrgbistro@users.noreply.github.com> Date: Thu, 23 Jul 2020 15:29:39 -0400 Subject: [PATCH 5/6] More filenames for modpack start scripts (#596) --- start-deployFTB | 3 +++ 1 file changed, 3 insertions(+) diff --git a/start-deployFTB b/start-deployFTB index eb455651..3af069a7 100644 --- a/start-deployFTB +++ b/start-deployFTB @@ -66,9 +66,12 @@ fi entryScriptExpr=" -name ServerStart.sh + -o -name serverstart.sh -o -name ServerStartLinux.sh -o -name LaunchServer.sh -o -name server-start.sh + -o -name startserver.sh + -o -name StartServer.sh " if [[ -d ${FTB_BASE_DIR} ]]; then From a486458a0804319df56b80b14eeb9f046d7f2652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20Z=C3=BChlcke?= Date: Sun, 26 Jul 2020 15:20:11 +0200 Subject: [PATCH 6/6] Fixed "REPLACE_ENV_VARIABLES_EXCLUDE_PATHS" breaking cfg replacer when set. (#598) --- README.md | 2 +- start-finalSetupEnvVariables | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 726d1297..aa12728c 100644 --- a/README.md +++ b/README.md @@ -329,7 +329,7 @@ Specific files can be excluded by listing their name (without path) in the varia Paths can be excluded by listing them in the variable `REPLACE_ENV_VARIABLES_EXCLUDE_PATHS`. Path excludes are recursive. Here is an example: ``` -REPLACE_ENV_VARIABLES_EXCLUDE_PATHS="/data/plugins/Essentials/userdata/ /data/plugins/MyPlugin/" +REPLACE_ENV_VARIABLES_EXCLUDE_PATHS="/data/plugins/Essentials/userdata /data/plugins/MyPlugin" ``` Here is a full example where we want to replace values inside a `database.yml`. diff --git a/start-finalSetupEnvVariables b/start-finalSetupEnvVariables index 4dfc04ca..ab8d13c8 100644 --- a/start-finalSetupEnvVariables +++ b/start-finalSetupEnvVariables @@ -6,20 +6,21 @@ if isTrue "${REPLACE_ENV_VARIABLES}"; then log "Replacing env variables in configs that match the prefix $ENV_VARIABLE_PREFIX..." - findExcludes= # File excludes + fileExcludes= for f in ${REPLACE_ENV_VARIABLES_EXCLUDES}; do - findExcludes="${findExcludes} -not -name $f" + fileExcludes="${fileExcludes} -not -name $f" done # Directory excludes (recursive) dirExcludes=$(join_by " -o -path " ${REPLACE_ENV_VARIABLES_EXCLUDE_PATHS}) if [[ $dirExcludes ]]; then - findExcludes+=" -type d ( -path ${dirExcludes} ) -prune" + dirExcludes=" -type d ( -path ${dirExcludes} ) -prune -o" fi - isDebugging && echo "Using find exclusions: $findExcludes" + isDebugging && echo "Using find file exclusions: $fileExcludes" + isDebugging && echo "Using find directory exclusions: $dirExcludes" while IFS='=' read -r name value ; do # check if name of env variable matches the prefix @@ -34,10 +35,12 @@ if isTrue "${REPLACE_ENV_VARIABLES}"; then fi log "Replacing $name with $value ..." - find /data/ -type f \ + find /data/ \ + $dirExcludes \ + -type f \ \( -name "*.yml" -or -name "*.yaml" -or -name "*.txt" -or -name "*.cfg" \ -or -name "*.conf" -or -name "*.properties" \) \ - $findExcludes \ + $fileExcludes \ -exec sed -i 's#${'"$name"'}#'"$value"'#g' {} \; fi done < <(env)