Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b7b3c69
remove unused functions
IronMine Oct 14, 2024
504bddd
feat : add specific logs for errors and warnings
IronMine Oct 15, 2024
d807c59
feat : WIP add error logs
IronMine Oct 15, 2024
8dc856e
feat : add error and warn logs
IronMine Oct 15, 2024
57c753e
fix : canyon modded jenkins url
IronMine Oct 15, 2024
eca4df7
fix : remove one curl call
IronMine Oct 15, 2024
7f8c240
fix and refactor
IronMine Oct 15, 2024
a19fb03
fix : use fail to
IronMine Oct 15, 2024
b68f896
refacto
IronMine Oct 15, 2024
af82fe5
maybe this could be better by setting globally the baseDataDir so if …
IronMine Oct 15, 2024
a325c9c
maybe ?
IronMine Oct 15, 2024
5e06277
revert failed commit
IronMine Oct 15, 2024
4967d45
Merge branch 'master' into refactor
IronMine Oct 15, 2024
8823db9
add error only log
IronMine Oct 15, 2024
8220101
refacto : add getCommandFromDistro
IronMine Oct 15, 2024
359a75a
refacto
IronMine Oct 15, 2024
4362b82
fix lost letter ^^
IronMine Oct 15, 2024
2a16fe5
refacto git credentials
IronMine Oct 16, 2024
9f12de9
refacto
IronMine Oct 16, 2024
beda0be
Merge branch 'master' into refactor
IronMine Oct 16, 2024
a4565c3
fix : PR comments
IronMine Oct 21, 2024
23a9f76
revert failed modification
IronMine Oct 21, 2024
3d2328e
maybe the way to go with debug mode
IronMine Oct 21, 2024
787e662
use args approach for better readable code
IronMine Oct 21, 2024
c021b36
fix : PR comments
IronMine Oct 22, 2024
0bfdca6
fix : start utils
IronMine Oct 22, 2024
510c48e
fix : logged string just disappears
IronMine Oct 22, 2024
f5bf3bc
fix : logged string just disappears
IronMine Oct 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions bin/mc-send-to-console
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,22 @@
: "${CONSOLE_IN_NAMED_PIPE:=/tmp/minecraft-console-in}"

if isFalse "${CREATE_CONSOLE_IN_PIPE:-false}"; then
echo "ERROR: console pipe needs to be enabled by setting CREATE_CONSOLE_IN_PIPE to true"
error "Console pipe needs to be enabled by setting CREATE_CONSOLE_IN_PIPE to true"
fi


if [ $# = 0 ]; then
echo "ERROR: pass console commands as arguments"
error "Pass console commands as arguments"
exit 1
fi

if [ ! -p "${CONSOLE_IN_NAMED_PIPE}" ]; then
echo "ERROR: named pipe ${CONSOLE_IN_NAMED_PIPE} is missing"
error "Named pipe ${CONSOLE_IN_NAMED_PIPE} is missing"
exit 1
fi

if [ "$(id -u)" = 0 -a $UID != 0 ]; then
if [[ $(getDistro) == alpine ]]; then
exec su-exec minecraft bash -c "echo '$*' > '${CONSOLE_IN_NAMED_PIPE:-/tmp/minecraft-console-in}'"
else
exec gosu minecraft bash -c "echo '$*' > '${CONSOLE_IN_NAMED_PIPE:-/tmp/minecraft-console-in}'"
fi
exec $(getSudoFromDistro) minecraft bash -c "echo '$*' > '${CONSOLE_IN_NAMED_PIPE}'"
else
echo "$@" >"${CONSOLE_IN_NAMED_PIPE:-/tmp/minecraft-console-in}"
echo "$@" >"${CONSOLE_IN_NAMED_PIPE}"
fi
8 changes: 4 additions & 4 deletions bin/mcstatus
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

echo "WARNING: mcstatus is deprecated; calling mc-monitor instead"
warning "mcstatus is deprecated; calling mc-monitor instead"

##### mcstatus shim for mc-monitor
# handles translating calls to
Expand All @@ -11,8 +11,8 @@ addr="$1"

IFS=':'
read -a parts <<< "${addr}"
args=(--host ${parts[0]})
if [[ ${#parts[*]} -gt 1 ]]; then
exec mc-monitor status --host ${parts[0]} --port ${parts[1]}
else
exec mc-monitor status --host ${parts[0]}
args+=(--port ${parts[1]})
fi
exec mc-monitor ${args[@]}
7 changes: 1 addition & 6 deletions scripts/start
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,7 @@ if ! isTrue "${SKIP_SUDO:-false}" && [ "$(id -u)" = 0 ]; then
echo 'hosts: files dns' > /etc/nsswitch.conf
fi

distro=$(getDistro)
if [[ $distro == alpine ]]; then
exec su-exec ${runAsUser}:${runAsGroup} "${SCRIPTS:-/}start-configuration" "$@"
else
exec gosu ${runAsUser}:${runAsGroup} "${SCRIPTS:-/}start-configuration" "$@"
fi
exec $(getSudoFromDistro) ${runAsUser}:${runAsGroup} "${SCRIPTS:-/}start-configuration" "$@"
else
exec "${SCRIPTS:-/}start-configuration" "$@"
fi
66 changes: 23 additions & 43 deletions scripts/start-autopause
Original file line number Diff line number Diff line change
Expand Up @@ -26,60 +26,40 @@ isDebugging && set -x

cp /auto/knockd-config.cfg /tmp/knockd-config.cfg

function updatePort() {
regseq="^\s*sequence\s*=\s*$1\s*$"
linenum=$(grep -nm${2} sequence /tmp/knockd-config.cfg | cut -d : -f 1 | tail -n1)
if ! [[ $(awk "NR==$linenum" /tmp/knockd-config.cfg) =~ $regseq ]]; then
sed -i "${linenum}s/sequence.*/sequence = $1/" /tmp/knockd-config.cfg
log "Updated $3 port in knockd config"
fi
}

# update server port to listen to
regseq="^\s*sequence\s*=\s*$SERVER_PORT\s*$"
linenum=$(grep -nm1 sequence /tmp/knockd-config.cfg | cut -d : -f 1 | tail -n1)
if ! [[ $(awk "NR==$linenum" /tmp/knockd-config.cfg) =~ $regseq ]]; then
sed -i "${linenum}s/sequence.*/sequence = $SERVER_PORT/" /tmp/knockd-config.cfg
log "Updated server port in knockd config"
fi
updatePort $SERVER_PORT 1 "server"

# update rcon port to listen to
regseq="^\s*sequence\s*=\s*$RCON_PORT\s*$"
linenum=$(grep -nm2 sequence /tmp/knockd-config.cfg | cut -d : -f 1 | tail -n1)
if ! [[ $(awk "NR==$linenum" /tmp/knockd-config.cfg) =~ $regseq ]]; then
sed -i "${linenum}s/sequence.*/sequence = $RCON_PORT/" /tmp/knockd-config.cfg
log "Updated rcon port in knockd config"
fi
updatePort $RCON_PORT 2 "rcon"

isNumericElseSetToDefault "AUTOPAUSE_PERIOD" 10
checkIfNotZeroElseSetToDefault "AUTOPAUSE_PERIOD" 10
isNumericElseSetToDefault "AUTOPAUSE_TIMEOUT_KN" 120
isNumericElseSetToDefault "AUTOPAUSE_TIMEOUT_EST" 3600
isNumericElseSetToDefault "AUTOPAUSE_TIMEOUT_INIT" 600

if ! [[ $AUTOPAUSE_PERIOD =~ ^[0-9]+$ ]]; then
AUTOPAUSE_PERIOD=10
export AUTOPAUSE_PERIOD
log "Warning: AUTOPAUSE_PERIOD is not numeric, set to 10 (seconds)"
fi
if [ "$AUTOPAUSE_PERIOD" -eq "0" ] ; then
AUTOPAUSE_PERIOD=10
export AUTOPAUSE_PERIOD
log "Warning: AUTOPAUSE_PERIOD must not be 0, set to 10 (seconds)"
fi
if ! [[ $AUTOPAUSE_TIMEOUT_KN =~ ^[0-9]+$ ]] ; then
AUTOPAUSE_TIMEOUT_KN=120
export AUTOPAUSE_TIMEOUT_KN
log "Warning: AUTOPAUSE_TIMEOUT_KN is not numeric, set to 120 (seconds)"
fi
if ! [[ $AUTOPAUSE_TIMEOUT_EST =~ ^[0-9]+$ ]] ; then
AUTOPAUSE_TIMEOUT_EST=3600
export AUTOPAUSE_TIMEOUT_EST
log "Warning: AUTOPAUSE_TIMEOUT_EST is not numeric, set to 3600 (seconds)"
fi
if ! [[ $AUTOPAUSE_TIMEOUT_INIT =~ ^[0-9]+$ ]] ; then
AUTOPAUSE_TIMEOUT_INIT=600
export AUTOPAUSE_TIMEOUT_INIT
log "Warning: AUTOPAUSE_TIMEOUT_INIT is not numeric, set to 600 (seconds)"
fi
if [[ "$AUTOPAUSE_KNOCK_INTERFACE" == "lo" ]] ; then
log "Warning: AUTOPAUSE_KNOCK_INTERFACE is set to the local loopback interface."
log " This is not advisable, as incoming connections are likely not picked up there."
log " Continuing with this setting."
logWarning "AUTOPAUSE_KNOCK_INTERFACE is set to the local loopback interface."
logWarning " This is not advisable, as incoming connections are likely not picked up there."
logWarning " Continuing with this setting."
fi

if [[ -n "$MAX_TICK_TIME" && "$MAX_TICK_TIME" != "-1" ]] ; then
log "Warning: MAX_TICK_TIME is non-default, for autopause to work properly, this check should be disabled (-1 for versions >= 1.8.1)"
logWarning "MAX_TICK_TIME is non-default, for autopause to work properly, this check should be disabled (-1 for versions >= 1.8.1)"
elif [[ -z "$MAX_TICK_TIME" ]] ; then
MAX_TICK_TIME=-1
if versionLessThan 1.8.1; then
# 10 years
MAX_TICK_TIME=315360000000
else
MAX_TICK_TIME=-1
fi
export MAX_TICK_TIME
fi
Expand Down
24 changes: 4 additions & 20 deletions scripts/start-autostop
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,9 @@ log "Autostop functionality enabled"

isDebugging && set -x

if ! [[ $AUTOSTOP_PERIOD =~ ^[0-9]+$ ]]; then
AUTOSTOP_PERIOD=10
export AUTOSTOP_PERIOD
log "Warning: AUTOSTOP_PERIOD is not numeric, set to 10 (seconds)"
fi
if [ "$AUTOSTOP_PERIOD" -eq "0" ] ; then
AUTOSTOP_PERIOD=10
export AUTOSTOP_PERIOD
log "Warning: AUTOSTOP_PERIOD must not be 0, set to 10 (seconds)"
fi
if ! [[ $AUTOSTOP_TIMEOUT_EST =~ ^[0-9]+$ ]] ; then
AUTOSTOP_TIMEOUT_EST=3600
export AUTOSTOP_TIMEOUT_EST
log "Warning: AUTOSTOP_TIMEOUT_EST is not numeric, set to 3600 (seconds)"
fi
if ! [[ $AUTOSTOP_TIMEOUT_INIT =~ ^[0-9]+$ ]] ; then
AUTOSTOP_TIMEOUT_INIT=1800
export AUTOSTOP_TIMEOUT_INIT
log "Warning: AUTOSTOP_TIMEOUT_INIT is not numeric, set to 1800 (seconds)"
fi
isNumericElseSetToDefault "AUTOSTOP_PERIOD" 10
checkIfNotZeroElseSetToDefault "AUTOSTOP_PERIOD" 10
isNumericElseSetToDefault "AUTOSTOP_TIMEOUT_EST" 3600
isNumericElseSetToDefault "AUTOSTOP_TIMEOUT_INIT" 1800

/auto/autostop-daemon.sh &
42 changes: 21 additions & 21 deletions scripts/start-configuration
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ log "Running as uid=$(id -u) gid=$(id -g) with /data as '$(ls -lnd /data)'"
if [ ! -e /data/eula.txt ]; then
if ! isTrue "$EULA"; then
log ""
log "Please accept the Minecraft EULA at"
log " https://account.mojang.com/documents/minecraft_eula"
log "by adding the following immediately after 'docker run':"
log " -e EULA=TRUE"
logError "Please accept the Minecraft EULA at"
logError " https://account.mojang.com/documents/minecraft_eula"
logError "by adding the following immediately after 'docker run':"
logError " -e EULA=TRUE"
log ""
exit 1
fi
Expand All @@ -63,10 +63,10 @@ if isTrue "${ENABLE_RCON:-true}"; then
if [[ -v RCON_PASSWORD_FILE ]]; then
if [ ! -e "${RCON_PASSWORD_FILE}" ]; then
log ""
log "Initial RCON password file ${RCON_PASSWORD_FILE} does not seems to exist."
log "Please ensure your configuration."
log "If you are using Docker Secrets feature, please check this for further information: "
log " https://docs.docker.com/engine/swarm/secrets"
logError "Initial RCON password file ${RCON_PASSWORD_FILE} does not seems to exist."
logError "Please ensure your configuration."
logError "If you are using Docker Secrets feature, please check this for further information: "
logError " https://docs.docker.com/engine/swarm/secrets"
log ""
exit 1
else
Expand All @@ -91,12 +91,12 @@ fi
# Auto-pause/stop

if isTrue "${ENABLE_AUTOPAUSE}" && isTrue "${EXEC_DIRECTLY:-false}"; then
log "EXEC_DIRECTLY=true is incompatible with ENABLE_AUTOPAUSE=true"
logError "EXEC_DIRECTLY=true is incompatible with ENABLE_AUTOPAUSE=true"
exit 1
fi

if isTrue "${ENABLE_AUTOPAUSE}" && isTrue "${ENABLE_AUTOSTOP}"; then
log "ENABLE_AUTOPAUSE=true is incompatible with ENABLE_AUTOSTOP=true"
logError "ENABLE_AUTOPAUSE=true is incompatible with ENABLE_AUTOSTOP=true"
exit 1
fi

Expand All @@ -112,9 +112,9 @@ function fixJavaPath() {
# Some Docker management UIs grab all the image declared variables and present them for configuration.
# When upgrading images across Java versions, that creates a mismatch in PATH's expected by base image.
if ! which java > /dev/null; then
log "ERROR: your Docker provider has an annoying flaw where it"
log " tries to set PATH even though the container establishes"
log " a very specific value."
logError " Your Docker provider has an annoying flaw where it"
logError " tries to set PATH even though the container establishes"
logError " a very specific value."
sleep 2
# now find where java might be
for d in /opt/java/openjdk/bin /usr/bin; do
Expand All @@ -129,7 +129,7 @@ function fixJavaPath() {


if ! fixJavaPath; then
log "ERROR: could not locate path that contains java"
logError "could not locate path that contains java"
exit 1
fi

Expand Down Expand Up @@ -184,7 +184,7 @@ if [[ $MOD_PLATFORM ]]; then
;;

*)
log "ERROR; Invalid MOD_PLATFORM: '$MOD_PLATFORM'"
logError "Invalid MOD_PLATFORM: '$MOD_PLATFORM'"
exit 1
;;
esac
Expand Down Expand Up @@ -219,7 +219,7 @@ case "${TYPE^^}" in
QUILT)
exec "${SCRIPTS:-/}start-deployQuilt" "$@"
;;

VANILLA)
exec "${SCRIPTS:-/}start-deployVanilla" "$@"
;;
Expand Down Expand Up @@ -273,11 +273,11 @@ case "${TYPE^^}" in
;;

*)
log "ERROR: Invalid TYPE: '$TYPE'"
log "Must be: VANILLA, FORGE, BUKKIT, SPIGOT, PAPER, FOLIA, PURPUR, FABRIC, QUILT,"
log " SPONGEVANILLA, CUSTOM, MAGMA, MOHIST, CATSERVER, AIRPLANE, PUFFERFISH,"
log " CANYON, LIMBO, CRUCIBLE"
logError "Invalid TYPE: '$TYPE'"
logError "Must be: VANILLA, FORGE, BUKKIT, SPIGOT, PAPER, FOLIA, PURPUR, FABRIC, QUILT,"
logError " SPONGEVANILLA, CUSTOM, MAGMA, MOHIST, CATSERVER, AIRPLANE, PUFFERFISH,"
logError " CANYON, LIMBO, CRUCIBLE"
exit 1
;;

esac
esac
8 changes: 2 additions & 6 deletions scripts/start-deployAutoCF
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,11 @@ setArg --exclude-include-file CF_EXCLUDE_INCLUDE_FILE
setArg --downloads-repo CF_DOWNLOADS_REPO

if ! mc-image-helper install-curseforge "${args[@]}"; then
log "ERROR failed to auto-install CurseForge modpack"
logError "Failed to auto-install CurseForge modpack"
exit 1
fi

# grab SERVER, TYPE, VERSION and export it
set -a
# shellcheck disable=SC1090
source "${resultsFile}"
set +a
applyResultsFile ${resultsFile}
resolveFamily

exec "${SCRIPTS:-/}start-setupWorld" "$@"
Loading