emu: Stop silent early exits in the emulator start script
The script's set -euo pipefail made it die without any visible error in two places: an empty /tmp/jtube-adbkeys/ failed the glob cat (the error itself was discarded, so the output just stopped mid-script — this hits any host after a reboot), and the boot-wait loop was killed on its first iteration because adb exits non-zero while the device is still booting. Both were swallowing the whole && chain (adb connect, scrcpy), making it look like the emulator was broken when it was fine or about to be. The stale bridge-emulator.sh duplicate (different port, broken vendor keys path) is removed in the same spirit — keeping it invites running the wrong script. Docs updated to match the one script.
This commit is contained in:
parent
c19024355c
commit
a71de07969
3 changed files with 22 additions and 49 deletions
|
|
@ -9,6 +9,12 @@ emulator works, and what needs to exist again after a rebuild.
|
||||||
`scripts/start-emulator.sh`). **Headless is the default**; set
|
`scripts/start-emulator.sh`). **Headless is the default**; set
|
||||||
`JTUBE_EMU_MODE=windowed` if you want the Qt window (e.g. for desktop
|
`JTUBE_EMU_MODE=windowed` if you want the Qt window (e.g. for desktop
|
||||||
interaction testing). View it via scrcpy either way.
|
interaction testing). View it via scrcpy either way.
|
||||||
|
- **Only the host can start the emulator** (by design — no SSH from the
|
||||||
|
container to the host, no SDK/KVM inside the container). If the agent
|
||||||
|
finds no emulator, it should tell the user to run
|
||||||
|
`./scripts/start-emulator.sh` on the host rather than try to work around
|
||||||
|
it. Reachability check: `adb connect rutherford:5556` then
|
||||||
|
`adb -s rutherford:5556 shell getprop sys.boot_completed` → `1`.
|
||||||
- **Agent container**: image `agent-container:latest`, container name pattern
|
- **Agent container**: image `agent-container:latest`, container name pattern
|
||||||
`ac-<project>-<hash>`, launched with **`--network host`** — it shares the
|
`ac-<project>-<hash>`, launched with **`--network host`** — it shares the
|
||||||
host's network namespace. This is load-bearing: see below.
|
host's network namespace. This is load-bearing: see below.
|
||||||
|
|
@ -46,7 +52,8 @@ So inside the container:
|
||||||
`/tmp/jtube-adbkeys/*.pub`) and launches the emulator with
|
`/tmp/jtube-adbkeys/*.pub`) and launches the emulator with
|
||||||
`ADB_VENDOR_KEYS` pointing at it. To trust a new client: put its
|
`ADB_VENDOR_KEYS` pointing at it. To trust a new client: put its
|
||||||
`~/.android/adbkey.pub` into `/tmp/jtube-adbkeys/` **before** launching.
|
`~/.android/adbkey.pub` into `/tmp/jtube-adbkeys/` **before** launching.
|
||||||
- Logs: `/tmp/jtube-emu.log` (QEMU) and `/tmp/jtube-emu-run.log` (script).
|
- Logs: `/tmp/jtube-emu.log` (QEMU), `/tmp/jtube-socat.log` (bridge),
|
||||||
|
`/tmp/jtube-adbkeys-combined` (rebuilt each launch).
|
||||||
- Viewing: `scrcpy -s emulator-5600` on the host, or from any LAN machine:
|
- Viewing: `scrcpy -s emulator-5600` on the host, or from any LAN machine:
|
||||||
`adb connect rutherford:5556 && scrcpy -s 127.0.0.1:5556`.
|
`adb connect rutherford:5556 && scrcpy -s 127.0.0.1:5556`.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
#
|
|
||||||
# bridge-emulator.sh — (host-side) expose the emulator's adbd to the LAN so agents
|
|
||||||
# inside the container/other machines can use it: binds :5557 -> 127.0.0.1:5601.
|
|
||||||
# The emulator console transport (emulator-5600) stays local-only; this bridges the
|
|
||||||
# adbd TCP port 5601.
|
|
||||||
set -euo pipefail
|
|
||||||
ADBD_PORT=5601
|
|
||||||
BRIDGE_PORT=5557
|
|
||||||
|
|
||||||
# start emulator if not running
|
|
||||||
ADB="${ANDROID_SDK_ROOT:-$HOME/Android/Sdk}/platform-tools/adb"
|
|
||||||
if ! "$ADB" devices | grep -q "emulator-5600.*device"; then
|
|
||||||
echo "emulator-5600 not running — starting it…"
|
|
||||||
ADB_VENDOR_KEYS="$HOME/.android/adbkey" setsid nohup \
|
|
||||||
"${ANDROID_SDK_ROOT:-$HOME/Android/Sdk}/emulator/emulator" -avd jtubesc -port 5600 \
|
|
||||||
-no-window -gpu swiftshader_indirect -no-snapshot -no-audio -no-boot-anim \
|
|
||||||
> /tmp/jtube-emu.log 2>&1 < /dev/null &
|
|
||||||
echo "waiting for boot (log: /tmp/jtube-emu.log)…"
|
|
||||||
for i in $(seq 1 60); do
|
|
||||||
ok=$("$ADB" -s emulator-5600 shell getprop sys.boot_completed 2>/dev/null | tr -d '\r')
|
|
||||||
[ "$ok" = "1" ] && { echo "BOOTED"; break; }
|
|
||||||
sleep 5
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
# keep JTube TV installed + running
|
|
||||||
APK="$HOME/Projects/jtube-tv/app/build/outputs/apk/debug/app-debug.apk"
|
|
||||||
if [ -f "$APK" ]; then
|
|
||||||
"$ADB" -s emulator-5600 install -r "$APK" >/dev/null && echo "JTube TV installed"
|
|
||||||
"$ADB" -s emulator-5600 shell am start -n net.jeena.jtubetv/.MainActivity && echo "app started"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# the bridge (bind all LAN addresses)
|
|
||||||
if ! ss -tln 2>/dev/null | grep -q ":$BRIDGE_PORT"; then
|
|
||||||
setsid nohup socat TCP-LISTEN:$BRIDGE_PORT,bind=0.0.0.0,fork,reuseaddr \
|
|
||||||
TCP:127.0.0.1:$ADBD_PORT > /tmp/jtube-bridge.log 2>&1 < /dev/null &
|
|
||||||
echo "bridge: :$BRIDGE_PORT -> 127.0.0.1:$ADBD_PORT (pid $!)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "From this host: adb connect localhost:$BRIDGE_PORT"
|
|
||||||
echo "From other machines: adb connect rutherford:$BRIDGE_PORT"
|
|
||||||
|
|
@ -62,11 +62,13 @@ if [ "$MODE" = windowed ]; then
|
||||||
else
|
else
|
||||||
echo "JTUBE_EMU_MODE=windowed but no display detected — falling back to headless"
|
echo "JTUBE_EMU_MODE=windowed but no display detected — falling back to headless"
|
||||||
WINDOWED=0
|
WINDOWED=0
|
||||||
ACCEL+=(-no-window)
|
ACCEL+=(-no-window -gpu swiftshader_indirect)
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
WINDOWED=0
|
WINDOWED=0
|
||||||
ACCEL+=(-no-window)
|
# Headless has no X display, so -gpu host/GLX can't init EGL ("Failed to get EGL
|
||||||
|
# display") and the emulator dies on launch — fall back to software rendering.
|
||||||
|
ACCEL+=(-no-window -gpu swiftshader_indirect)
|
||||||
echo "headless (default; JTUBE_EMU_MODE=windowed for a window) — no emulator window"
|
echo "headless (default; JTUBE_EMU_MODE=windowed for a window) — no emulator window"
|
||||||
fi
|
fi
|
||||||
if [ -e /dev/kvm ]; then
|
if [ -e /dev/kvm ]; then
|
||||||
|
|
@ -79,21 +81,27 @@ fi
|
||||||
# blocked, so remote keys are trusted via ADB_VENDOR_KEYS at launch instead.
|
# blocked, so remote keys are trusted via ADB_VENDOR_KEYS at launch instead.
|
||||||
# Drop extra public keys into /tmp/jtube-adbkeys/ (one per file), e.g. from the
|
# Drop extra public keys into /tmp/jtube-adbkeys/ (one per file), e.g. from the
|
||||||
# agent container: docker exec <ctr> sh -c 'cat ~/.android/adbkey.pub' > /tmp/jtube-adbkeys/agent-container.pub
|
# agent container: docker exec <ctr> sh -c 'cat ~/.android/adbkey.pub' > /tmp/jtube-adbkeys/agent-container.pub
|
||||||
|
mkdir -p /tmp/jtube-adbkeys
|
||||||
VKEYS=/tmp/jtube-adbkeys-combined
|
VKEYS=/tmp/jtube-adbkeys-combined
|
||||||
{
|
{
|
||||||
cat "$HOME/.android/adbkey.pub"
|
cat "$HOME/.android/adbkey.pub"
|
||||||
cat /tmp/jtube-adbkeys/*.pub 2>/dev/null
|
# Optional extra keys — must not fail the script under `set -e` when absent.
|
||||||
|
shopt -s nullglob
|
||||||
|
for k in /tmp/jtube-adbkeys/*.pub; do cat "$k"; done
|
||||||
|
shopt -u nullglob
|
||||||
} > "$VKEYS"
|
} > "$VKEYS"
|
||||||
chmod 600 "$VKEYS"
|
chmod 600 "$VKEYS"
|
||||||
|
|
||||||
echo "Booting AVD '$AVD' …"
|
echo "Booting AVD '$AVD' …"
|
||||||
ADB_VENDOR_KEYS="$VKEYS" setsid nohup "$EMU" -avd "$AVD" -port "$PORT" -gpu host "${ACCEL[@]:-}" \
|
ADB_VENDOR_KEYS="$VKEYS" setsid nohup "$EMU" -avd "$AVD" -port "$PORT" "${ACCEL[@]:-}" \
|
||||||
-no-snapshot > /tmp/jtube-emu.log 2>&1 < /dev/null &
|
-no-snapshot > /tmp/jtube-emu.log 2>&1 < /dev/null &
|
||||||
echo "emulator PID $! — log: /tmp/jtube-emu.log"
|
echo "emulator PID $! — log: /tmp/jtube-emu.log"
|
||||||
|
|
||||||
for i in $(seq 1 90); do
|
for i in $(seq 1 90); do
|
||||||
ok=$("$ADB" -s "emulator-$PORT" shell getprop sys.boot_completed 2>/dev/null | tr -d '\r')
|
# adb exits non-zero while the device is still booting — don't let
|
||||||
[ "$ok" = "1" ] && { echo "BOOTED"; break; }
|
# pipefail+set -e kill the wait loop.
|
||||||
|
ok=$( ("$ADB" -s "emulator-$PORT" shell getprop sys.boot_completed 2>/dev/null || true) | tr -d '\r')
|
||||||
|
if [ "$ok" = "1" ]; then echo "BOOTED"; break; fi
|
||||||
sleep 5
|
sleep 5
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue