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

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=lib.sh
source "${SCRIPT_DIR}/lib.sh"

HEAD_IP="$(container_ip "${HEAD_CONTAINER}")"

echo "[head] ray stop (best-effort)"
dexec "${HEAD_CONTAINER}" bash -lc "ray stop --force || true"

echo "[head] start ray head (CPU=0 GPU=0): ${HEAD_IP}"
dexec "${HEAD_CONTAINER}" bash -lc "ray start --head --node-ip-address='${HEAD_IP}' --port=6379 --dashboard-host=0.0.0.0 --dashboard-port=8265 --num-cpus=0 --num-gpus=0 --disable-usage-stats"

echo "[head] ray status"
dexec "${HEAD_CONTAINER}" bash -lc "ray status || true"

