#!/usr/bin/env bash # Gitea push 후 chatbot.exdev.co.kr 배포 완료 대기 set -euo pipefail EXDEV_SSH="${EXDEV_SSH:-aidev@chatbot.exdev.co.kr}" DEPLOY_LOG="${DEPLOY_LOG:-/Volumes/ADATA/logs/deploy/exAichatbot_agent.log}" PUBLIC_URL="${PUBLIC_BASE_URL:-https://chatbot.exdev.co.kr}/chatbot/ai/" MAX_WAIT="${DEPLOY_WAIT_SEC:-900}" log() { echo "[wait-deploy] $*"; } ssh_cmd() { ssh -o BatchMode=yes -o ConnectTimeout=15 "${EXDEV_SSH}" "$@" } if ! ssh_cmd "test -f '${DEPLOY_LOG}'" 2>/dev/null; then log "배포 로그 없음 — SSH로 deploy 스크립트 직접 실행" ssh_cmd "bash /Volumes/ADATA/git/deploy-exAichatbot_agent.sh" || true fi log "배포 완료 대기 (최대 ${MAX_WAIT}s) — ${EXDEV_SSH}" start_ts="$(date +%s)" deadline=$((start_ts + MAX_WAIT)) while (( $(date +%s) < deadline )); do if curl -sf --max-time 5 "${PUBLIC_URL}" 2>/dev/null | grep -q 'data-chatbot-app'; then log "✅ UI 응답: ${PUBLIC_URL}" ssh_cmd "tail -8 '${DEPLOY_LOG}'" 2>/dev/null || true exit 0 fi if ssh_cmd "grep -q '배포 완료' '${DEPLOY_LOG}'" 2>/dev/null; then last_line="$(ssh_cmd "tail -1 '${DEPLOY_LOG}'" 2>/dev/null || true)" if [[ "${last_line}" == *"배포 완료"* ]]; then log "✅ 배포 로그 확인" ssh_cmd "tail -8 '${DEPLOY_LOG}'" 2>/dev/null || true exit 0 fi fi sleep 10 done log "⚠️ 배포 대기 타임아웃 — 로그 확인: ssh ${EXDEV_SSH} tail -50 ${DEPLOY_LOG}" exit 1