#!/bin/bash # fix-cloudrun.sh — sjekker og restarter Cloud Run-tjeneste # Bruk: bash scripts/fix/fix-cloudrun.sh osvauco-agent set -uo pipefail SERVICE=${1:-osvauco-agent} PROJECT=${PROJECTID:-propane-will-491900-m5} REGION=${REGION:-us-central1} echo "=====================================" echo " CLOUD RUN FIX — $SERVICE" echo "=====================================" # 1. Status echo "\n[1/3] Henter status..." STATUS=$(gcloud run services describe "$SERVICE" \ --project="$PROJECT" --region="$REGION" \ --format="value(status.conditions[0].type,status.conditions[0].status)" 2>/dev/null || echo "FEIL") echo " Status: $STATUS" # 2. Siste revisjon og URL echo "\n[2/3] Siste revisjon og URL..." gcloud run services describe "$SERVICE" \ --project="$PROJECT" --region="$REGION" \ --format="table(status.latestReadyRevisionName,status.url)" 2>/dev/null || echo " Klarte ikke hente" # 3. Health-sjekk echo "\n[3/3] Health-sjekk..." SVC_URL=$(gcloud run services describe "$SERVICE" \ --project="$PROJECT" --region="$REGION" \ --format="value(status.url)" 2>/dev/null || echo "") if [ -n "$SVC_URL" ]; then TOKEN=$(gcloud auth print-identity-token 2>/dev/null) HTTP=$(curl -sI -o /dev/null -w "%{http_code}" \ -H "Authorization: Bearer $TOKEN" \ --max-time 10 "${SVC_URL}/health" || echo "000") echo " /health → HTTP $HTTP" if [ "$HTTP" = "200" ]; then echo " ✅ Cloud Run OK" else echo " ❌ Ikke OK — sjekk logs:" echo " gcloud run services logs read $SERVICE --project=$PROJECT --region=$REGION --limit=50" fi else echo " ❌ Klarte ikke hente service URL" fi echo "\n=====================================" echo " Logs: gcloud run services logs read $SERVICE --project=$PROJECT --region=$REGION --limit=50" echo "====================================="