Files
MCM/start.sh

64 lines
2.1 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# MCM MultiCustomerMessenger Startskript
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# Virtuelle Umgebung
PYTHON=".venv/bin/python"
if [ ! -x "$PYTHON" ]; then
echo "Fehler: .venv nicht gefunden. Bitte erst 'python -m venv .venv && .venv/bin/pip install -r requirements.txt' ausführen."
exit 1
fi
# Lokale IP ermitteln
LOCAL_IP=$(python3 -c "
import socket
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('8.8.8.8', 80))
print(s.getsockname()[0])
s.close()
except Exception:
print('localhost')
")
# Ports aus .env lesen (Fallback auf Standardwerte)
API_PORT=$(grep -E '^PORT=' .env 2>/dev/null | cut -d= -f2 | tr -d '[:space:]')
WEB_PORT=$(grep -E '^WEB_PORT=' .env 2>/dev/null | cut -d= -f2 | tr -d '[:space:]')
API_PORT=${API_PORT:-8000}
WEB_PORT=${WEB_PORT:-8001}
echo ""
echo "╔══════════════════════════════════════════════════╗"
echo "║ MCM MultiCustomerMessenger ║"
echo "╠══════════════════════════════════════════════════╣"
echo "║ REST-API : http://${LOCAL_IP}:${API_PORT} "
echo "║ Web-TUI : http://${LOCAL_IP}:${WEB_PORT} "
echo "╚══════════════════════════════════════════════════╝"
echo ""
# Web-TUI im Hintergrund starten
echo "[1/2] Starte Web-TUI (Port $WEB_PORT)..."
"$PYTHON" serve_tui.py --host 0.0.0.0 --port "$WEB_PORT" &
TUI_PID=$!
# Kurz warten damit die TUI hochfährt
sleep 1
# API starten (Vordergrund)
echo "[2/2] Starte API (Port $API_PORT)..."
"$PYTHON" main_api_only.py &
API_PID=$!
echo ""
echo "Beide Dienste gestartet. Ctrl+C zum Beenden."
echo ""
# Auf Ctrl+C warten und beide Prozesse beenden
trap "echo ''; echo 'MCM wird beendet...'; kill $TUI_PID $API_PID 2>/dev/null; wait $TUI_PID $API_PID 2>/dev/null; echo 'Beendet.'" INT TERM
wait $API_PID