"Refactor: Rename and restructure guide file for separate backend servers"
This commit is contained in:
parent
31b538185a
commit
03ff4260e2
@ -37,51 +37,124 @@ cd "$SCRIPT_DIR"
|
|||||||
|
|
||||||
log_info "Arbeitsverzeichnis: $SCRIPT_DIR"
|
log_info "Arbeitsverzeichnis: $SCRIPT_DIR"
|
||||||
|
|
||||||
|
# Umgebungsmodus bestimmen
|
||||||
|
if [ "$1" = "--production" ] || [ "$FLASK_ENV" = "production" ]; then
|
||||||
|
RUN_MODE="production"
|
||||||
|
log_info "Produktionsmodus aktiviert"
|
||||||
|
elif [ "$1" = "--development" ] || [ "$FLASK_ENV" = "development" ]; then
|
||||||
|
RUN_MODE="development"
|
||||||
|
log_info "Entwicklungsmodus aktiviert"
|
||||||
|
else
|
||||||
|
RUN_MODE="development"
|
||||||
|
log_info "Standard-Entwicklungsmodus aktiviert"
|
||||||
|
fi
|
||||||
|
|
||||||
# Umgebungsvariablen laden
|
# Umgebungsvariablen laden
|
||||||
if [ -f ".env.backend" ]; then
|
if [ -f "env.backend" ]; then
|
||||||
log_info "Lade Backend-Umgebungsvariablen..."
|
log_info "Lade Backend-Umgebungsvariablen..."
|
||||||
export $(cat .env.backend | grep -v '^#' | xargs)
|
export $(cat env.backend | grep -v '^#' | grep -v '^$' | xargs)
|
||||||
|
export FLASK_ENV="$RUN_MODE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Prüfe Docker-Installation
|
# Prüfe Python-Installation
|
||||||
if ! command -v docker &> /dev/null; then
|
if ! command -v python3 &> /dev/null; then
|
||||||
log_error "Docker ist nicht installiert!"
|
log_error "Python3 ist nicht installiert!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! command -v docker-compose &> /dev/null; then
|
# Prüfe pip-Installation
|
||||||
log_error "Docker Compose ist nicht installiert!"
|
if ! command -v pip3 &> /dev/null; then
|
||||||
|
log_error "pip3 ist nicht installiert!"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log_success "Docker-Installation verifiziert"
|
log_success "Python-Installation verifiziert"
|
||||||
|
|
||||||
# Alte Container stoppen und entfernen
|
# Erstelle virtuelle Umgebung falls nicht vorhanden
|
||||||
log_info "Stoppe eventuell laufende Backend-Container..."
|
if [ ! -d "venv" ]; then
|
||||||
docker-compose -f docker-compose.backend.yml down --remove-orphans 2>/dev/null || true
|
log_info "Erstelle virtuelle Python-Umgebung..."
|
||||||
|
python3 -m venv venv
|
||||||
# Images aufräumen (optional)
|
|
||||||
if [ "$1" = "--clean" ]; then
|
|
||||||
log_info "Räume alte Backend-Images auf..."
|
|
||||||
docker-compose -f docker-compose.backend.yml down --rmi all --volumes 2>/dev/null || true
|
|
||||||
docker system prune -f
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Aktiviere virtuelle Umgebung
|
||||||
|
log_info "Aktiviere virtuelle Umgebung..."
|
||||||
|
source venv/bin/activate
|
||||||
|
|
||||||
|
# Installiere Dependencies
|
||||||
|
log_info "Installiere Python-Dependencies..."
|
||||||
|
pip install --upgrade pip
|
||||||
|
pip install -r requirements.txt
|
||||||
|
|
||||||
# Notwendige Verzeichnisse erstellen
|
# Notwendige Verzeichnisse erstellen
|
||||||
log_info "Erstelle notwendige Verzeichnisse..."
|
log_info "Erstelle notwendige Verzeichnisse..."
|
||||||
mkdir -p instance logs migrations/versions config
|
mkdir -p instance logs migrations/versions
|
||||||
|
|
||||||
# Backend-Container builden und starten
|
# Datenbank initialisieren
|
||||||
log_info "Backend-Container werden gebaut und gestartet..."
|
log_info "Initialisiere Datenbank..."
|
||||||
docker-compose -f docker-compose.backend.yml up --build -d
|
export FLASK_APP=app.py
|
||||||
|
python3 -c "
|
||||||
|
from app import create_app, init_db
|
||||||
|
app = create_app('$RUN_MODE')
|
||||||
|
with app.app_context():
|
||||||
|
init_db()
|
||||||
|
print('Datenbank initialisiert')
|
||||||
|
"
|
||||||
|
|
||||||
# Warten auf Backend-Start
|
# Drucker initialisieren
|
||||||
log_info "Warte auf Backend-Service..."
|
if [ ! -z "$PRINTERS" ]; then
|
||||||
timeout=120
|
log_info "Initialisiere Drucker-Konfiguration..."
|
||||||
counter=0
|
python3 -c "
|
||||||
|
from app import create_app, init_printers
|
||||||
|
app = create_app('$RUN_MODE')
|
||||||
|
with app.app_context():
|
||||||
|
init_printers()
|
||||||
|
print('Drucker initialisiert')
|
||||||
|
"
|
||||||
|
fi
|
||||||
|
|
||||||
while [ $counter -lt $timeout ]; do
|
# Server starten basierend auf Modus
|
||||||
if curl -f http://localhost:5000/health >/dev/null 2>&1; then
|
if [ "$RUN_MODE" = "production" ]; then
|
||||||
|
log_info "Starte Backend-Server im Produktionsmodus..."
|
||||||
|
log_info "Verwende Gunicorn für Produktionsbetrieb"
|
||||||
|
|
||||||
|
# Prüfe ob Gunicorn installiert ist
|
||||||
|
if ! command -v gunicorn &> /dev/null; then
|
||||||
|
log_error "Gunicorn ist nicht installiert! Installiere mit: pip install gunicorn"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Starte mit Produktions-Skript
|
||||||
|
exec ./start-production.sh
|
||||||
|
|
||||||
|
else
|
||||||
|
log_info "Starte Backend-Server im Entwicklungsmodus..."
|
||||||
|
|
||||||
|
# Flask-Entwicklungsserver
|
||||||
|
export FLASK_APP=app.py
|
||||||
|
export FLASK_ENV=development
|
||||||
|
export FLASK_DEBUG=1
|
||||||
|
|
||||||
|
# Port prüfen
|
||||||
|
PORT=${PORT:-5000}
|
||||||
|
if netstat -tuln | grep -q ":$PORT "; then
|
||||||
|
log_warning "Port $PORT ist bereits belegt!"
|
||||||
|
log_info "Verwende alternativen Port 5001..."
|
||||||
|
PORT=5001
|
||||||
|
fi
|
||||||
|
|
||||||
|
log_info "Backend-Server startet auf Port $PORT..."
|
||||||
|
|
||||||
|
# Flask-Server starten
|
||||||
|
python3 -m flask run --host=0.0.0.0 --port=$PORT &
|
||||||
|
FLASK_PID=$!
|
||||||
|
|
||||||
|
# Warten auf Server-Start
|
||||||
|
log_info "Warte auf Backend-Service..."
|
||||||
|
timeout=60
|
||||||
|
counter=0
|
||||||
|
|
||||||
|
while [ $counter -lt $timeout ]; do
|
||||||
|
if curl -f http://localhost:$PORT/health >/dev/null 2>&1; then
|
||||||
log_success "Backend-Server ist bereit!"
|
log_success "Backend-Server ist bereit!"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
@ -92,39 +165,31 @@ while [ $counter -lt $timeout ]; do
|
|||||||
|
|
||||||
sleep 1
|
sleep 1
|
||||||
counter=$((counter + 1))
|
counter=$((counter + 1))
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ $counter -eq $timeout ]; then
|
if [ $counter -eq $timeout ]; then
|
||||||
log_error "Backend-Service konnte nicht gestartet werden!"
|
log_error "Backend-Service konnte nicht gestartet werden!"
|
||||||
log_info "Zeige Backend-Logs:"
|
kill $FLASK_PID 2>/dev/null || true
|
||||||
docker-compose -f docker-compose.backend.yml logs backend
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Migrationen ausführen
|
# URLs anzeigen
|
||||||
log_info "Führe Datenbank-Migrationen aus..."
|
echo ""
|
||||||
docker-compose -f docker-compose.backend.yml exec backend flask db upgrade || log_warning "Migrationen fehlgeschlagen oder nicht erforderlich"
|
log_success "🎉 Backend-Server erfolgreich gestartet!"
|
||||||
|
echo ""
|
||||||
|
echo "📡 Backend-API: http://localhost:$PORT"
|
||||||
|
echo "🔧 Backend-Health: http://localhost:$PORT/health"
|
||||||
|
echo "📋 Backend-Test: http://localhost:$PORT/api/test"
|
||||||
|
echo ""
|
||||||
|
|
||||||
# Service-Status anzeigen
|
# Logs anzeigen (optional)
|
||||||
log_info "Backend-Service Status:"
|
if [ "$2" = "--logs" ] || [ "$3" = "--logs" ]; then
|
||||||
docker-compose -f docker-compose.backend.yml ps
|
|
||||||
|
|
||||||
# URLs anzeigen
|
|
||||||
echo ""
|
|
||||||
log_success "🎉 Backend-Server erfolgreich gestartet!"
|
|
||||||
echo ""
|
|
||||||
echo "📡 Backend-API: http://localhost:5000"
|
|
||||||
echo "🔧 Backend-Health: http://localhost:5000/health"
|
|
||||||
echo "📋 Backend-Swagger: http://localhost:5000/swagger"
|
|
||||||
echo "🗄️ PostgreSQL: localhost:5432"
|
|
||||||
echo "⚡ Redis-Cache: localhost:6379"
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
# Logs anzeigen (optional)
|
|
||||||
if [ "$1" = "--logs" ] || [ "$2" = "--logs" ]; then
|
|
||||||
log_info "Zeige Backend-Logs (Strg+C zum Beenden):"
|
log_info "Zeige Backend-Logs (Strg+C zum Beenden):"
|
||||||
docker-compose -f docker-compose.backend.yml logs -f
|
tail -f logs/myp.log 2>/dev/null || log_warning "Keine Log-Datei gefunden"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log_info "Verwende 'docker-compose -f docker-compose.backend.yml logs -f' um Logs zu verfolgen"
|
log_info "Verwende Strg+C um den Server zu stoppen"
|
||||||
log_info "Verwende 'docker-compose -f docker-compose.backend.yml down' um den Server zu stoppen"
|
|
||||||
|
# Warte auf Signal
|
||||||
|
wait $FLASK_PID
|
||||||
|
fi
|
Loading…
x
Reference in New Issue
Block a user