diff --git a/scripts/thothii-local.sh b/scripts/thothii-local.sh new file mode 100755 index 00000000..a2312948 --- /dev/null +++ b/scripts/thothii-local.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env bash +# thothii-local.sh — avvia, ferma e controlla lo stack locale ThothII tramite tht. +# +# Prima di avviare ferma gli altri progetti Compose thothii-* in esecuzione (solo stop: container +# e volumi restano) e verifica che le porte pubblicate siano libere. PeopleKitchens non viene +# toccato: lo script segnala solo che è attivo. +# Uso: ./scripts/thothii-local.sh start [--build] | stop | status +set -euo pipefail + +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)" +INSTALLATION="$ROOT/deploy/psd/thothii-installation.yaml" +PORTS=(8080 8787 6333) + +tht_cmd() { + tht --installation "$INSTALLATION" "$@" +} + +running_thothii_projects() { + docker ps --filter 'label=com.docker.compose.project' \ + --format '{{.Label "com.docker.compose.project"}}' | sort -u | grep '^thothii' || true +} + +warn_peoplekitchens() { + if docker ps --format '{{.Names}}' | grep -q '^peoplekitchens'; then + echo "ATTENZIONE: container PeopleKitchens attivi (consumo memoria, non fermati da questo script)." >&2 + fi +} + +stop_other_thothii_projects() { + local project + while read -r project; do + [[ -n "$project" ]] || continue + echo "Fermo il progetto Compose $project (container e volumi conservati)" + docker compose -p "$project" stop + done < <(running_thothii_projects) +} + +check_ports_free() { + local port busy=0 + for port in "${PORTS[@]}"; do + if lsof -nP -iTCP:"$port" -sTCP:LISTEN >/dev/null 2>&1; then + echo "ERRORE: porta $port occupata da:" >&2 + lsof -nP -iTCP:"$port" -sTCP:LISTEN >&2 || true + busy=1 + fi + done + return "$busy" +} + +case "${1:-}" in + start) + shift + warn_peoplekitchens + tht_cmd stop >/dev/null 2>&1 || true + stop_other_thothii_projects + check_ports_free + tht_cmd start "$@" + ;; + stop) + tht_cmd stop + stop_other_thothii_projects + ;; + status) + tht_cmd status + echo "--- progetti thothii in esecuzione:" + running_thothii_projects + warn_peoplekitchens + ;; + *) + echo "Uso: $0 start [--build] | stop | status" >&2 + exit 2 + ;; +esac