#!/bin/bash
set -e

# Load ports from config
if [ -f /app/triton_ports.env ]; then
    export $(grep -v '^#' /app/triton_ports.env | xargs)
fi


echo "[INFO] Starting Triton servers with the following ports:"
echo "Face  - HTTP:$FACE_HTTP_PORT  GRPC:$FACE_GRPC_PORT  METRICS:$FACE_METRICS_PORT"

# Start Triton server #2 (Face detection, preprocess, postprocess) in background
tritonserver \
  --model-repository=/root/face_models \
  --http-port=$FACE_HTTP_PORT \
  --grpc-port=$FACE_GRPC_PORT \
  --metrics-port=$FACE_METRICS_PORT &

# Wait a bit to ensure Triton servers are up
sleep 5

# Run DeepStream app (expects configs under /app/data): (foreground, keeps container alive)
cd /app/build
./bin/BodyPipeline
