chore(uno-q): enforce a single node app in recover.sh
Add a single-app invariant step: set the boot default to the canonical app, stop any stray *-main-1 container that would collide on :8080/:9999, and ensure the canonical app is running. Prevents the duplicate-"ZeroClaw Node" collision from recurring after a reboot/re-plug. Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
feeff6ac9b
commit
c761c510a6
+28
-6
@@ -6,9 +6,11 @@
|
||||
# showing a fresh random claim code the API never received. This makes it all
|
||||
# consistent again in one pass:
|
||||
# 1. re-forward the adb tunnels (:8080 gateway, :9999 matrix relay)
|
||||
# 2. wait for the node daemon (start the App Lab app if it isn't up)
|
||||
# 3. re-register the node with the local API (restores its in-memory binding)
|
||||
# 4. scroll a fixed claim code on the matrix so the board + API agree
|
||||
# 2. assert the single-app invariant (canonical app is the boot default + the
|
||||
# only thing on :8080/:9999; stop any stray duplicate)
|
||||
# 3. wait for the node daemon (start the App Lab app if it isn't up)
|
||||
# 4. re-register the node with the local API (restores its in-memory binding)
|
||||
# 5. scroll a fixed claim code on the matrix so the board + API agree
|
||||
#
|
||||
# Usage:
|
||||
# ./recover.sh # one recovery pass, then exit
|
||||
@@ -27,6 +29,7 @@ KIT_ID="${KIT_ID:-crimson-node}"
|
||||
CLAIM_CODE="${CLAIM_CODE:-7777}"
|
||||
NODE_URL="${NODE_URL:-http://127.0.0.1:8080}"
|
||||
APP="${APP:-/home/arduino/ArduinoApps/apess-onboard}"
|
||||
CONTAINER="${APP##*/}-main-1" # App Lab names the container <app>-main-1
|
||||
PORTS=(8080 9999)
|
||||
|
||||
# Resolve adb even under launchd's minimal PATH.
|
||||
@@ -61,7 +64,26 @@ recover_once() {
|
||||
done
|
||||
ok "tunnels forwarded (${PORTS[*]})"
|
||||
|
||||
# 2 · wait for the node daemon (auto-starts on boot; start it if not)
|
||||
# 2 · single-app invariant: the canonical node app owns :8080/:9999. Make it
|
||||
# the boot default, stop any OTHER user app (a stray duplicate would collide on
|
||||
# our ports), and ensure it's the running container.
|
||||
"$ADB" -s "$SERIAL" shell "arduino-app-cli properties set default $APP" >/dev/null 2>&1
|
||||
local strays
|
||||
strays="$("$ADB" -s "$SERIAL" shell \
|
||||
"docker ps --format '{{.Names}}' 2>/dev/null | grep -E '\-main-1$' | grep -v '^${CONTAINER}$'" 2>/dev/null | tr -d '\r')"
|
||||
if [ -n "$strays" ]; then
|
||||
warn "stopping stray app container(s): $strays"
|
||||
for c in $strays; do
|
||||
"$ADB" -s "$SERIAL" shell "docker stop $c" >/dev/null 2>&1 || true
|
||||
done
|
||||
fi
|
||||
if ! "$ADB" -s "$SERIAL" shell "docker ps --format '{{.Names}}'" 2>/dev/null | grep -q "^${CONTAINER}$"; then
|
||||
warn "node app not running — starting ${APP##*/}"
|
||||
"$ADB" -s "$SERIAL" shell "arduino-app-cli app start $APP" >/dev/null 2>&1 || true
|
||||
fi
|
||||
ok "single-app invariant (default + only ${APP##*/} on ${PORTS[*]})"
|
||||
|
||||
# 3 · wait for the node daemon (auto-starts on boot; start it if not)
|
||||
local n=0
|
||||
until curl -s -m2 "$NODE_URL/health" -o /dev/null 2>/dev/null; do
|
||||
n=$((n + 1))
|
||||
@@ -74,7 +96,7 @@ recover_once() {
|
||||
done
|
||||
ok "node daemon healthy"
|
||||
|
||||
# 3 · re-register with the local API (restores the in-memory node binding)
|
||||
# 4 · re-register with the local API (restores the in-memory node binding)
|
||||
local r
|
||||
r="$(curl -s -m5 -X POST "$API/nodes/self-register" \
|
||||
-H "x-fleet-secret: $FLEET_SECRET" -H 'content-type: application/json' \
|
||||
@@ -82,7 +104,7 @@ recover_once() {
|
||||
if echo "$r" | grep -q '"url"'; then ok "re-registered with API (code $CLAIM_CODE)"
|
||||
else warn "API self-register failed — is the API up at $API? ($r)"; return 1; fi
|
||||
|
||||
# 4 · sync the claim code onto the matrix so board + API agree
|
||||
# 5 · sync the claim code onto the matrix so board + API agree
|
||||
matrix_code && ok "matrix showing $CLAIM_CODE" || warn "could not set matrix code (relay :9999)"
|
||||
log "recovered — bind in the UI with code $CLAIM_CODE"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user