Spaces:
Sleeping
Sleeping
| set -euo pipefail | |
| # venv activate (FastAPI side) | |
| if [ -f "/home/user/app/.venv/bin/activate" ]; then | |
| source /home/user/app/.venv/bin/activate | |
| fi | |
| export PORT="${PORT:-7860}" | |
| echo "[entrypoint] starting robot-server OT-2 on 127.0.0.1:31950..." | |
| (cd /root/opentrons && make -C robot-server dev-ot2 dev_host=127.0.0.1 dev_port=31950) > /tmp/robot-ot2.log 2>&1 & | |
| PID_OT2=$! | |
| echo "[entrypoint] starting robot-server Flex on 127.0.0.1:31951..." | |
| (cd /root/opentrons && make -C robot-server dev-flex dev_host=127.0.0.1 dev_port=31951) > /tmp/robot-flex.log 2>&1 & | |
| PID_FLEX=$! | |
| wait_port () { | |
| local name="$1" | |
| local port="$2" | |
| local log="$3" | |
| local pid="$4" | |
| echo "[entrypoint] waiting for ${name} (127.0.0.1:${port})..." | |
| for i in {1..90}; do | |
| if (echo > /dev/tcp/127.0.0.1/${port}) >/dev/null 2>&1; then | |
| echo "[entrypoint] ${name} is up" | |
| return 0 | |
| fi | |
| if ! kill -0 "${pid}" >/dev/null 2>&1; then | |
| echo "[entrypoint] ${name} exited early. Last logs:" | |
| tail -n 200 "${log}" || true | |
| return 1 | |
| fi | |
| sleep 1 | |
| done | |
| echo "[entrypoint] ${name} did not start in time. Last logs:" | |
| tail -n 200 "${log}" || true | |
| return 1 | |
| } | |
| wait_port "robot-server OT-2" 31950 /tmp/robot-ot2.log "${PID_OT2}" | |
| wait_port "robot-server Flex" 31951 /tmp/robot-flex.log "${PID_FLEX}" | |
| echo "[entrypoint] starting FastAPI on 0.0.0.0:${PORT} ..." | |
| exec uvicorn api:app --app-dir /home/user/app --host 0.0.0.0 --port "${PORT}" | |