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

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

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

echo "[head] ray start (CPU=0, GPU=0 to prevent scheduling on head)"
HEAD_IP="$(container_ip "${HEAD_CONTAINER}")"
echo "[head] container ip: ${HEAD_IP}"
dexec "${HEAD_CONTAINER}" bash -lc "ray start --head --node-ip-address=${HEAD_IP} --dashboard-host=0.0.0.0 --dashboard-port=8265 --port=6379 --num-cpus=0 --num-gpus=0"

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