Add PRE_START_SCRIPT, run after setup and before the server starts (#4293)

This commit is contained in:
u9g
2026-09-25 09:15:48 -05:00
committed by GitHub
parent 79a5346182
commit f3fe8284e5
3 changed files with 43 additions and 0 deletions
+16
View File
@@ -209,6 +209,22 @@ By default, the image finishes startup by exec'ing [mc-server-runner](https://gi
> [!TIP]
> The `SERVER_RUNNER` variable is expanded when passed to `exec` so that `mc-server-runner` can be wrapped by another executable that is mounted into the container.
## Pre-start script
To run something of your own after the image has finished setting up the server files and just before it starts the server, set `PRE_START_SCRIPT` to the path of an executable file that you have mounted into the container. The image runs it directly (not through a shell) and waits for it to finish. It runs as the user the server runs as, from the server's working directory, with the same environment the server gets. If it exits with a non-zero status, the container exits without starting the server.
For example, a script that waits for plugin jars that another process is still downloading:
```yaml
environment:
PRE_START_SCRIPT: /hooks/wait-for-plugins
volumes:
- ./hooks:/hooks:ro
```
> [!WARNING]
> The image does not guarantee that any particular command is available to the script, and it may change between image versions. Keeping the script working is up to you.
## Enable Flare Flags
To enable the JVM flags required to fully support the [Flare profiling suite](https://blog.airplane.gg/flare), set the following variable:
+6
View File
@@ -288,6 +288,12 @@ alternatively, you can mount: <code>/etc/localtime:/etc/localtime:ro
<td><code>false</code></td>
<td>⬜️</td>
</tr>
<tr>
<td><code>PRE_START_SCRIPT</code></td>
<td>Path to an executable run after setup and just before the server starts. The server is not started if it exits non-zero. See <a href="../configuration/misc-options/#pre-start-script">Pre-start script</a></td>
<td><code></code></td>
<td>⬜️</td>
</tr>
<tr>
<td><code>USE_FLARE_FLAGS</code></td>
<td>To enable the JVM flags required to fully support the <a href="https://blog.airplane.gg/flare">Flare profiling suite</a>.</td>
+21
View File
@@ -4,10 +4,27 @@
: "${SETUP_ONLY:=false}"
: "${CUSTOM_JAR_EXEC:=}"
: "${SERVER_RUNNER:=mc-server-runner}"
: "${PRE_START_SCRIPT:=}"
# shellcheck source=start-utils
. "$(dirname "$0")/start-utils"
isDebugging && set -x
function runPreStartScript() {
if [[ ! $PRE_START_SCRIPT ]]; then
return
fi
if [[ ! -x $PRE_START_SCRIPT ]]; then
logError "PRE_START_SCRIPT $PRE_START_SCRIPT is not an executable file"
exit 1
fi
log "Running pre-start script $PRE_START_SCRIPT..."
if ! "$PRE_START_SCRIPT"; then
logError "Pre-start script $PRE_START_SCRIPT failed, so the server will not be started"
exit 1
fi
}
baseDataDir=/data
tmpServerIconPath=/tmp/icon.img
serverIconPath=${baseDataDir}/server-icon.png
@@ -505,6 +522,7 @@ if [[ ${TYPE} == "CURSEFORGE" && "${SERVER}" ]]; then
exit 1
fi
log "Starting CurseForge server in ${FTB_DIR}..."
runPreStartScript
if isTrue "${DEBUG_EXEC}"; then
set -x
fi
@@ -569,6 +587,7 @@ fi
JVM_ARGS=${JVM_ARGS//$'\n'/}
sed -i "s~JAVA_ARGS=.*~JAVA_ARGS=\"${JVM_ARGS}\"~" "${FTB_DIR}/variables.txt"
fi
runPreStartScript
exec ${SERVER_RUNNER} "${mcServerRunnerArgs[@]}" -- "${finalArgs[@]}"
elif [[ $SERVER =~ run.sh ]]; then
log "Using Forge supplied run.sh script..."
@@ -577,6 +596,7 @@ elif [[ $SERVER =~ run.sh ]]; then
echo "SETUP_ONLY: bash ${SERVER}"
exit
fi
runPreStartScript
if isTrue "${DEBUG_EXEC}"; then
set -x
fi
@@ -614,6 +634,7 @@ else
exit
fi
runPreStartScript
if isTrue "${DEBUG_EXEC}"; then
set -x
fi