#!/bin/bash

# Start Nginx
service nginx start

# Start the Python HTTP server to serve static files
python -m http.server --directory ./static --bind 0.0.0.0 8000 & echo $! > http_server.pid

# Start the Uvicorn server for the backend
uvicorn "app:app" --port 7860 --host 0.0.0.0 &

# Start the Unity game server using xvfb-run
xvfb-run --auto-servernum --server-args='-screen 0 640x480x24:32' /home/pn/app/build/linuxBuild.x86_64 -batchmode -nographics -port 7777 &

# Wait for Uvicorn to finish
wait

# Stop the Python HTTP server
pkill -F http_server.pid
rm http_server.pid