Dump logs

This commit is contained in:
Colin Seymour
2026-06-15 14:44:10 +00:00
+28 -3
View File
@@ -506,11 +506,16 @@ configure_and_start_teslamate() {
if [ "$state" = "started" ]; then
break
fi
if [ "$state" = "error" ]; then
dump_teslamate_logs 50
err "TeslaMate addon failed to start (state: ${state})"
fi
debug "Attempt $((attempt + 1))/${max_attempts}: TeslaMate state=${state}"
sleep 5
attempt=$((attempt + 1))
done
if [ "$state" != "started" ]; then
dump_teslamate_logs 50
err "TeslaMate addon did not start in time (state: ${state})"
fi
@@ -518,23 +523,43 @@ configure_and_start_teslamate() {
ok "TeslaMate addon started and ready"
}
# dump_teslamate_logs() prints the most recent add-on logs (full lines) so a
# startup failure shows its real cause. It closes any open GitHub Actions log
# group first so the output is never hidden inside a collapsed fold.
dump_teslamate_logs() {
local lines="${1:-50}"
group_end
warn "Last ${lines} lines of TeslaMate add-on logs:"
supervisor_api GET "/addons/${TESLAMATE_SLUG}/logs" 2>/dev/null | tail -n "${lines}" >&2 || true
}
wait_for_teslamate_ready() {
log "Waiting for TeslaMate to be ready (listening on port ${TESLAMATE_PORT})..."
local max_attempts=60
local attempt=0
local logs state
while [ "$attempt" -lt "$max_attempts" ]; do
local logs
logs=$(supervisor_api GET "/addons/${TESLAMATE_SLUG}/logs" 2>/dev/null || true)
if echo "$logs" | grep -q "TeslaMateWeb.Endpoint"; then
ok "TeslaMate is ready"
return 0
fi
if [ "$DEBUG" = "1" ]; then
debug "Attempt $((attempt + 1))/${max_attempts}: endpoint not up yet; last log: $(echo "$logs" | tail -n 1)"
# TeslaMate's s6 finish script halts the whole container if the service
# exits non-zero, so a crash during startup shows up as the add-on leaving
# the "started" state. Detect that and fail immediately with the real logs
# instead of polling uselessly until the timeout.
state=$(supervisor_api_jq "/addons/${TESLAMATE_SLUG}/info" '.data.state')
if [ "$state" = "error" ] || [ "$state" = "stopped" ]; then
dump_teslamate_logs 50
err "TeslaMate crashed during startup (add-on state: ${state})"
fi
debug "Attempt $((attempt + 1))/${max_attempts}: endpoint not up yet (state=${state})"
sleep 5
attempt=$((attempt + 1))
done
dump_teslamate_logs 50
err "TeslaMate did not become ready in time (never saw 'TeslaMateWeb.Endpoint' in logs)"
}