Spaces:
Running
Running
File size: 1,999 Bytes
7aeb58b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | #!/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
|