#!/usr/bin/env bash
set -euo pipefail

DOCKER_DIR="/opt/hx-ki/docker"
cd "$DOCKER_DIR"

echo "=> Backup docker-compose.yml ..."
cp docker-compose.yml docker-compose.yml.bak_orchestra_$(date +%Y%m%d_%H%M%S)

echo "=> Entferne Service 'hxki-web' aus docker-compose.yml ..."
awk '
  /^[[:space:]]*hxki-web:/ { in_blk=1; next }
  in_blk && NF==0 { in_blk=0; next }
  !in_blk { print }
' docker-compose.yml > docker-compose.yml.tmp

mv docker-compose.yml.tmp docker-compose.yml

echo "=> Orchester starten ..."
docker compose up -d --remove-orphans
