mini_fleet / scripts /sim_fleet.sh
jonathanberi's picture
Fleet dashboard: polling, reset to known state, laptop + robot-app modes, sim harness
7aeb58b verified
Raw History Blame Contribute Delete
2 kB
#!/usr/bin/env bash
# Start / stop a fleet of simulated Reachy Mini daemons on one machine.
#
# scripts/sim_fleet.sh start [N] # N robots on ports 8000..8000+N-1 (default 3)
# scripts/sim_fleet.sh stop
# scripts/sim_fleet.sh status
#
# Uses --mockup-sim (no MuJoCo, no window). Robot names: sim-1..sim-N.
# Caveat: apps launched by any of these daemons connect their SDK client to
# localhost:8000, so keep a daemon on 8000. Daemons started from the same venv
# also share installed apps.
set -euo pipefail
RUN_DIR="${SIM_FLEET_DIR:-${TMPDIR:-/tmp}/mini_fleet_sims}"
BASE_PORT="${SIM_FLEET_BASE_PORT:-8000}"
mkdir -p "$RUN_DIR"
start() {
local n="${1:-3}"
for i in $(seq 1 "$n"); do
local port=$((BASE_PORT + i - 1))
if curl -sf -m 1 "localhost:$port/api/daemon/status" >/dev/null; then
echo "port $port already has a daemon, skipping"; continue
fi
nohup reachy-mini-daemon --mockup-sim --headless --no-media \
--robot-name "sim-$i" --fastapi-port "$port" \
>"$RUN_DIR/sim-$i.log" 2>&1 &
echo $! >"$RUN_DIR/sim-$i.pid"
done
for i in $(seq 1 "$n"); do
local port=$((BASE_PORT + i - 1))
for _ in $(seq 1 40); do
curl -sf -m 1 "localhost:$port/api/daemon/status" >/dev/null && break
sleep 0.5
done
done
status
}
stop() {
for f in "$RUN_DIR"/sim-*.pid; do
[ -e "$f" ] || continue
kill "$(cat "$f")" 2>/dev/null || true
rm -f "$f"
done
echo "stopped"
}
status() {
for f in "$RUN_DIR"/sim-*.pid; do
[ -e "$f" ] || { echo "no sims running"; return; }
local name; name=$(basename "$f" .pid)
local port=$((BASE_PORT + ${name#sim-} - 1))
if curl -sf -m 1 "localhost:$port/api/daemon/status" >/dev/null; then
echo "$name localhost:$port up"
else
echo "$name localhost:$port DOWN (log: $RUN_DIR/$name.log)"
fi
done
}
case "${1:-}" in
start) start "${2:-3}" ;;
stop) stop ;;
status) status ;;
*) echo "usage: $0 start [N] | stop | status"; exit 1 ;;
esac