Skip to content

Commit 4bf8836

Browse files
authored
feat: support container restarts (#300)
1 parent 24d2a47 commit 4bf8836

1 file changed

Lines changed: 56 additions & 44 deletions

File tree

src/runtime/start.sh

Lines changed: 56 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ CONFIG_DIR="${SCRIPT_DIR}/config"
1010
OVERRIDES_CONFIG_DIR="${CONFIG_DIR}/overrides"
1111
CUE_DIR="${CONFIG_DIR}/cue"
1212

13+
IS_SERVER_RESTART=false
14+
15+
if [ ! -d "${CUE_DIR}" ]; then
16+
echo '🔄 Restarting PaperMC server...'
17+
IS_SERVER_RESTART=true
18+
else
19+
echo '🚀 Starting PaperMC server for the first time...'
20+
fi
21+
1322
## JVM arguments
1423
# server.properties: https://minecraft.wiki/w/Server.properties
1524
# bukkit.yml: https://bukkit.fandom.com/wiki/Bukkit.yml
@@ -63,52 +72,55 @@ SERVER_ARGS="
6372

6473
cd "${ROOT_DIR}"
6574

66-
echo '⚙️ Preparing PaperMC server configuration files...'
67-
68-
TMP="$(envsubst '$EULA' < eula.txt)"
69-
echo "${TMP}" > eula.txt
70-
echo '🧾 File eula.txt processed'
71-
72-
# TODO: support help.yml
73-
# TODO: support ops.json
74-
# TODO: support whitelist.json
75-
# TODO: disable permissions.yml?
76-
# TODO: support custom Spark plugin version
77-
# TODO: Ensure Timings v2 is disabled by default
78-
# TODO: add tests verifying properties are well customized as expected
79-
80-
if [ -d "${OVERRIDES_CONFIG_DIR}" ] && [ -n "$(find "${OVERRIDES_CONFIG_DIR}" -maxdepth 1 -type f \( -name '*.yml' -o -name '*.yaml' \))" ]; then
81-
echo "📝 Custom YAML overrides configuration files have been found in ${OVERRIDES_CONFIG_DIR}."
82-
echo '📥 Importing them...'
83-
cd "${OVERRIDES_CONFIG_DIR}"
84-
cue import --package paper --outfile "${CUE_DIR}/overrides.cue" --ext yml --ext yaml
85-
else
86-
echo "ℹ️ No custom YAML overrides configuration files found in ${OVERRIDES_CONFIG_DIR}."
75+
if [ "${IS_SERVER_RESTART}" = false ]; then
76+
echo '⚙️ Preparing PaperMC server configuration files...'
77+
78+
# shellcheck disable=SC2016 # Use single quotes to prevent variable expansion with envsubst
79+
TMP="$(envsubst '$EULA' < eula.txt)"
80+
echo "${TMP}" > eula.txt
81+
echo '🧾 File eula.txt processed.'
82+
83+
# TODO: support help.yml
84+
# TODO: support ops.json
85+
# TODO: support whitelist.json
86+
# TODO: disable permissions.yml?
87+
# TODO: support custom Spark plugin version
88+
# TODO: Ensure Timings v2 is disabled by default
89+
# TODO: add tests verifying properties are well customized as expected
90+
91+
if [ -d "${OVERRIDES_CONFIG_DIR}" ] && [ -n "$(find "${OVERRIDES_CONFIG_DIR}" -maxdepth 1 -type f \( -name '*.yml' -o -name '*.yaml' \))" ]; then
92+
echo "📝 Custom YAML overrides configuration files have been found in ${OVERRIDES_CONFIG_DIR}."
93+
echo '📥 Importing them...'
94+
cd "${OVERRIDES_CONFIG_DIR}"
95+
cue import --package paper --outfile "${CUE_DIR}/overrides.cue" --ext yml --ext yaml
96+
else
97+
echo "ℹ️ No custom YAML overrides configuration files found in ${OVERRIDES_CONFIG_DIR}."
98+
fi
99+
100+
cd "${CUE_DIR}"
101+
102+
# Validate configuration values
103+
# TODO: more execution trace messages
104+
cue vet --concrete
105+
106+
# Generate the configuration files
107+
ENVVAR="$(env | grep -E '^(BUKKIT_|SPIGOT_|PAPER_)' | tr '\n' ',' | head -c -1)"
108+
109+
echo "📦 Generating configuration files..."
110+
cue export --inject "${ENVVAR}" -e 'bukkit.global' --out yaml --outfile "${ROOT_DIR}/bukkit.yml"
111+
cue export --inject "${ENVVAR}" -e 'bukkit.commands' --out yaml --outfile "${CONFIG_DIR}/commands.yml"
112+
cue export --inject "${ENVVAR}" -e 'bukkit.permissions' --out yaml --outfile "${CONFIG_DIR}/permissions.yml"
113+
cue export --inject "${ENVVAR}" -e 'spigot' --out yaml --outfile "${CONFIG_DIR}/spigot.yml"
114+
cue export --inject "${ENVVAR}" -e 'paper.global' --out yaml --outfile "${CONFIG_DIR}/paper-global.yml"
115+
cue export --inject "${ENVVAR}" -e 'paper["worlds-defaults"]' --out yaml --outfile "${CONFIG_DIR}/paper-world-defaults.yml"
116+
echo '✅ Configuration files successfully generated!'
117+
118+
# Clean-up CUE files after config generation
119+
rm -rf "${CUE_DIR}"
120+
121+
echo '✨ PaperMC server ready to start!'
87122
fi
88123

89-
cd "${CUE_DIR}"
90-
91-
# Validate configuration values
92-
# TODO: more execution trace messages
93-
cue vet --concrete
94-
95-
# Generate the configuration files
96-
ENVVAR="$(env | grep -E '^(BUKKIT_|SPIGOT_|PAPER_)' | tr '\n' ',' | head -c -1)"
97-
98-
echo "📦 Generating configuration files..."
99-
cue export --inject "${ENVVAR}" -e 'bukkit.global' --out yaml --outfile "${ROOT_DIR}/bukkit.yml"
100-
cue export --inject "${ENVVAR}" -e 'bukkit.commands' --out yaml --outfile "${CONFIG_DIR}/commands.yml"
101-
cue export --inject "${ENVVAR}" -e 'bukkit.permissions' --out yaml --outfile "${CONFIG_DIR}/permissions.yml"
102-
cue export --inject "${ENVVAR}" -e 'spigot' --out yaml --outfile "${CONFIG_DIR}/spigot.yml"
103-
cue export --inject "${ENVVAR}" -e 'paper.global' --out yaml --outfile "${CONFIG_DIR}/paper-global.yml"
104-
cue export --inject "${ENVVAR}" -e 'paper["worlds-defaults"]' --out yaml --outfile "${CONFIG_DIR}/paper-world-defaults.yml"
105-
echo '✅ Configuration files successfully generated!'
106-
107-
# Clean-up CUE files after config generation
108-
rm -rf "${CUE_DIR}"
109-
110124
cd "${ROOT_DIR}"
111125

112-
echo '✨ PaperMC server ready to start!'
113-
114126
exec java $JVM_ARGUMENTS -jar "${SCRIPT_DIR}"/papermc-server-*.jar $SERVER_ARGS

0 commit comments

Comments
 (0)