185 lignes
9.1 KiB
Bash
185 lignes
9.1 KiB
Bash
#!/bin/bash
|
|
# Déploie GastinelTpa 1.2.0 sur cornafserver (inclut la 1.1.1 : recharge 1 s silencieuse, délai TPA caché, messages).
|
|
# Nouveautés 1.2.0 : /tpacancel, homes (/sethome /home /delhome /homes), protection RTP, message de mort privé.
|
|
#
|
|
# bash deployer-tpa-1-2-0.sh # déploie (jar attendu à côté du script, dans ~/staging/deploiement-tpa-1-2-0/)
|
|
# bash deployer-tpa-1-2-0.sh --avec-guide # idem + copie le texte du /guide (gastinelmind-guide.json, voir plus bas)
|
|
# bash deployer-tpa-1-2-0.sh --retour # remet le jar 1.1.0 et l'ancienne config, puis redémarre
|
|
#
|
|
# Ne redémarre que minecraft-neoforge, avec : docker compose --env-file ~/server-infra/.env up -d --force-recreate
|
|
# (depuis ~/server-infra/stacks/minecraft-neoforge). Le conteneur est d'abord ARRÊTÉ proprement (compose stop) pour que
|
|
# l'édition de la config ne soit pas "corrigée" à chaud par le jar 1.1.0 encore en service (clés inconnues).
|
|
# Aucune commande de ce script ne touche aux autres conteneurs ni aux autres mods.
|
|
set -uo pipefail
|
|
|
|
STACK="$HOME/server-infra/stacks/minecraft-neoforge"
|
|
ENVFILE="$HOME/server-infra/.env"
|
|
DATA="$STACK/data"
|
|
MODS="$DATA/mods"
|
|
CFG="$DATA/config/gastineltpa-server.toml"
|
|
GUIDE="$DATA/config/gastinelmind-guide.json"
|
|
SRC="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
SUFFIXE="avant-tpa-1-2-0"
|
|
CONTENEUR="minecraft-neoforge"
|
|
NOUVEAU="gastineltpa-neoforge-1.21.1-1.2.0.jar"
|
|
ANCIEN="gastineltpa-neoforge-1.21.1-1.1.0.jar"
|
|
SAUV="$HOME/staging/sauvegardes-$SUFFIXE"
|
|
AVEC_GUIDE=0
|
|
RETOUR=0
|
|
for a in "$@"; do
|
|
case "$a" in
|
|
--retour) RETOUR=1 ;;
|
|
--avec-guide) AVEC_GUIDE=1 ;;
|
|
*) echo "Option inconnue : $a"; exit 1 ;;
|
|
esac
|
|
done
|
|
|
|
log() { echo "[$(date '+%F %T')] $*"; }
|
|
rcon() { docker exec "$CONTENEUR" rcon-cli "$@" 2>/dev/null || true; }
|
|
compose() { (cd "$STACK" && docker compose --env-file "$ENVFILE" "$@"); }
|
|
|
|
prevenir_et_sauver() {
|
|
local n; n=$(rcon list | sed -n 's/.*There are \([0-9]*\) of.*/\1/p' | head -1); n=${n:-0}
|
|
log "Joueurs connectés : $n"; rcon list
|
|
if [ "$n" -gt 0 ]; then
|
|
rcon say "Redémarrage du serveur dans 60 s (mise à jour : homes, /tpacancel, protection /rtp). Durée : environ 2 min."
|
|
sleep 30; rcon say "Redémarrage dans 30 s."
|
|
sleep 20; rcon say "Redémarrage dans 10 s. Sauvegarde du monde…"
|
|
sleep 10
|
|
fi
|
|
rcon save-all flush
|
|
sleep 5
|
|
}
|
|
|
|
verifier_pas_de_generation() {
|
|
if docker logs --since 10m "$CONTENEUR" 2>&1 | grep -qiE "chunky.*(task|tâche).*(running|progress)|\[Chunky\].*[0-9]+\.[0-9]+%"; then
|
|
log "ERREUR : génération Chunky en cours. Abandon."; exit 2
|
|
fi
|
|
local actifs
|
|
actifs=$(pgrep -aif "bonsai|tache.?75" | grep -v -e pgrep -e "sleep [0-9]" || true)
|
|
if [ -n "$actifs" ]; then log "ERREUR : processus Bonsai / tâche 75 en cours. Abandon."; exit 2; fi
|
|
}
|
|
|
|
# Attend que le conteneur soit "healthy" ET que le serveur ait fini de démarrer ("Done (").
|
|
attendre_sain() {
|
|
local depuis="$1" debut=$SECONDS st
|
|
for _ in $(seq 1 120); do
|
|
sleep 5
|
|
st=$(docker inspect -f '{{if .State.Health}}{{.State.Health.Status}}{{else}}sans-healthcheck{{end}}' "$CONTENEUR" 2>/dev/null || echo absent)
|
|
if [ "$st" = "healthy" ] && docker logs --since "$depuis" "$CONTENEUR" 2>&1 | grep -q 'Done ('; then
|
|
log "Serveur démarré et healthy en $((SECONDS - debut)) s."; return 0
|
|
fi
|
|
if [ "$st" = "absent" ] || [ "$st" = "exited" ]; then log "Conteneur absent/arrêté pendant le démarrage ($st)."; return 1; fi
|
|
done
|
|
log "Pas healthy après 10 min."; return 1
|
|
}
|
|
|
|
redemarrer() { # recrée et démarre (compose), puis attend
|
|
local t; t=$(date -u +%Y-%m-%dT%H:%M:%SZ)
|
|
log "docker compose up -d --force-recreate ($CONTENEUR)"
|
|
compose up -d --force-recreate || { log "ERREUR : docker compose up a échoué."; return 1; }
|
|
attendre_sain "$t"
|
|
}
|
|
|
|
verifier_log() {
|
|
local depuis="$1" ok=0 l c
|
|
l=$(docker logs --since "$depuis" "$CONTENEUR" 2>&1)
|
|
echo "$l" | grep -q 'Done (' || { log "KO : pas de démarrage complet"; ok=1; }
|
|
echo "$l" | grep -qiE 'Mixin apply.*failed|InvalidInjectionException|Crash report|Failed to load mod' && { log "KO : erreur de mod/mixin"; ok=1; }
|
|
echo "$l" | grep -q '\[GastinelTpa\] Téléportations chargées' || { log "KO : GastinelTpa non chargé"; ok=1; }
|
|
echo "$l" | grep -q '\[GastinelAuth\] Mod initialisé' || { log "KO : GastinelAuth non initialisé"; ok=1; }
|
|
echo "$l" | grep -qE 'Homes : .*illisible' && { log "KO : fichier de homes illisible"; ok=1; }
|
|
for _ in 1 2 3 4 5 6; do
|
|
docker logs --since "$depuis" "$CONTENEUR" 2>&1 | grep -q 'Voice chat server started at port 24454' && break; sleep 5
|
|
done
|
|
docker logs --since "$depuis" "$CONTENEUR" 2>&1 | grep -q 'Voice chat server started at port 24454' || { log "KO : chat vocal non démarré"; ok=1; }
|
|
# Lancées depuis la console : une commande qui existe répond autre chose que "Unknown or incomplete command"
|
|
# (ex. "joueur requis"). Avec un argument factice pour tpa/tpahere (sinon "incomplete" même si elle existe).
|
|
for c in "spawn" "rtp" "tpa x" "tpahere x" "tpaccept" "tpadeny" "tpacancel" "sethome" "home" "delhome" "homes"; do
|
|
if rcon "$c" | grep -q 'Unknown or incomplete command'; then log "KO : commande /${c%% *} absente"; ok=1; else log "Commande /${c%% *} : présente"; fi
|
|
done
|
|
return $ok
|
|
}
|
|
|
|
# Remet jar 1.1.0 + ancienne config (arrête d'abord le serveur) et redémarre.
|
|
retour_arriere() {
|
|
log "RETOUR ARRIÈRE : jar 1.1.0 + ancienne config"
|
|
compose stop -t 120 "$CONTENEUR" >/dev/null 2>&1 || true
|
|
rm -f "$MODS/$NOUVEAU"
|
|
[ -f "$MODS/$ANCIEN.$SUFFIXE" ] && mv -f "$MODS/$ANCIEN.$SUFFIXE" "$MODS/$ANCIEN"
|
|
[ -f "$CFG.$SUFFIXE" ] && cp -f "$CFG.$SUFFIXE" "$CFG"
|
|
redemarrer || log "ERREUR : redémarrage impossible après retour arrière, intervention manuelle."
|
|
rcon list
|
|
}
|
|
|
|
appliquer_config() {
|
|
# Recharges /spawn et /rtp = 1 s (limité à chaque section), puis sections/clés absentes (idempotent).
|
|
sed -i '/^\[spawn\]/,/^\[/ s/^\([ \t]*rechargeSecondes[ \t]*=[ \t]*\).*/\11/' "$CFG"
|
|
sed -i '/^\[rtp\]/,/^\[/ s/^\([ \t]*rechargeSecondes[ \t]*=[ \t]*\).*/\11/' "$CFG"
|
|
grep -q '^\[recharge\]' "$CFG" || printf '\n[recharge]\n\tafficherMessageRecharge = false\n' >> "$CFG"
|
|
grep -q '^\[tpa\]' "$CFG" || printf '\n[tpa]\n\tdelaiSecondes = 1\n' >> "$CFG"
|
|
grep -q '^\[homes\]' "$CFG" || printf '\n[homes]\n\tmaximum = 3\n\trechargeSecondes = 1\n\tdelaiSecondes = 3\n' >> "$CFG"
|
|
if ! grep -q 'protectionSecondes' "$CFG"; then
|
|
awk '{ print } /^\[rtp\][ \t]*$/ && !fait { print "\tprotectionSecondes = 15"; print "\tprotectionFinSiAttaque = true"; fait = 1 }' \
|
|
"$CFG" > "$CFG.nouveau" && cat "$CFG.nouveau" > "$CFG" && rm -f "$CFG.nouveau"
|
|
fi
|
|
log "Config appliquée : recharges 1 s, [recharge] afficherMessageRecharge=false, [tpa] delaiSecondes=1, [homes], rtp.protection*."
|
|
grep -nE '^\[|rechargeSecondes|afficherMessageRecharge|delaiSecondes|maximum|protection' "$CFG" || true
|
|
}
|
|
|
|
if [ "$RETOUR" = 1 ]; then
|
|
[ -f "$MODS/$ANCIEN.$SUFFIXE" ] || { log "Rien à restaurer : $MODS/$ANCIEN.$SUFFIXE absent."; exit 1; }
|
|
prevenir_et_sauver
|
|
retour_arriere
|
|
exit 0
|
|
fi
|
|
|
|
[ -f "$SRC/$NOUVEAU" ] || { log "Jar manquant : $SRC/$NOUVEAU"; exit 1; }
|
|
[ -f "$MODS/$ANCIEN" ] || { log "Ancien jar absent : $MODS/$ANCIEN (déjà déployé ?)"; exit 1; }
|
|
[ -f "$CFG" ] || { log "Config absente : $CFG"; exit 1; }
|
|
[ -f "$ENVFILE" ] || { log "Fichier d'environnement absent : $ENVFILE"; exit 1; }
|
|
[ -f "$STACK/docker-compose.yml" ] || { log "docker-compose.yml absent dans $STACK"; exit 1; }
|
|
[ "$AVEC_GUIDE" = 0 ] || [ -f "$SRC/gastinelmind-guide.json" ] || { log "--avec-guide : $SRC/gastinelmind-guide.json absent"; exit 1; }
|
|
verifier_pas_de_generation
|
|
|
|
mkdir -p "$SAUV"
|
|
HORO=$(date +%Y%m%d-%H%M%S)
|
|
cp -a "$CFG" "$SAUV/gastineltpa-server.toml.$HORO"
|
|
cp -a "$MODS/$ANCIEN" "$SAUV/$ANCIEN.$HORO"
|
|
log "Config et ancien jar sauvegardés dans $SAUV"
|
|
|
|
prevenir_et_sauver
|
|
|
|
# Section critique : le serveur est arrêté ; en cas d'échec quelconque on remet l'ancien état puis on redémarre.
|
|
ARRET=$(date '+%T')
|
|
log "Arrêt propre de $CONTENEUR (compose stop)"
|
|
if ! compose stop -t 120 "$CONTENEUR"; then
|
|
log "ERREUR : arrêt impossible, rien n'a été modifié."; exit 1
|
|
fi
|
|
cp -a "$CFG" "$CFG.$SUFFIXE"
|
|
if mv -f "$MODS/$ANCIEN" "$MODS/$ANCIEN.$SUFFIXE" && cp "$SRC/$NOUVEAU" "$MODS/$NOUVEAU" && appliquer_config; then
|
|
log "Jar remplacé (ancien : $ANCIEN.$SUFFIXE)."
|
|
else
|
|
log "DÉPLOIEMENT KO : copie ou config impossible."
|
|
retour_arriere
|
|
exit 1
|
|
fi
|
|
|
|
DEBUT=$(date -u +%Y-%m-%dT%H:%M:%SZ)
|
|
if redemarrer && verifier_log "$DEBUT"; then
|
|
log "DÉPLOIEMENT OK (arrêt à $ARRET, de nouveau disponible à $(date '+%T'))."
|
|
rcon list
|
|
else
|
|
log "DÉPLOIEMENT KO : retour arrière automatique."
|
|
docker logs --since "$DEBUT" "$CONTENEUR" 2>&1 | grep -iE 'error|exception' | head -30 || true
|
|
retour_arriere
|
|
exit 1
|
|
fi
|
|
|
|
# Texte du /guide (relu à chaud par GastinelMindPNJ, aucun redémarrage requis). Seulement avec --avec-guide.
|
|
if [ "$AVEC_GUIDE" = 1 ]; then
|
|
if [ -f "$GUIDE" ]; then cp -a "$GUIDE" "$SAUV/gastinelmind-guide.json.$HORO"; fi
|
|
cp "$SRC/gastinelmind-guide.json" "$GUIDE"
|
|
log "Texte du /guide mis à jour (sauvegarde : $SAUV/gastinelmind-guide.json.$HORO)."
|
|
fi
|