homelab-codex-ws/scripts/lib/diagnostics.sh

54 lines
1.6 KiB
Bash
Raw Permalink Normal View History

2026-05-11 21:20:13 +02:00
#!/usr/bin/env bash
# diagnostics.sh - Deployment failure diagnostics
collect_diagnostics() {
local host=$1
local service=$2
log "INFO" "Stage: DIAGNOSE ($host - ${service:-all})"
local diag_file="${LOG_DIR}/diagnostics_${TIMESTAMP}.txt"
{
echo "--- DIAGNOSTICS FOR ${service:-all} (Host: $host, Time: $(date)) ---"
echo "Uptime: $(uptime)"
echo "Memory: $(free -h)"
echo "Disk: $(df -h /)"
echo "--- Docker Status ---"
docker ps --filter "name=${service:-}"
if [[ -n "$service" ]]; then
local svc_dir="${REPO_PATH}/services/$service"
if [[ -d "$svc_dir" ]]; then
echo "--- $service Logs ---"
cd "$svc_dir" && docker compose logs --tail=50
fi
fi
echo "--- END DIAGNOSTICS ---"
} > "$diag_file" 2>&1
# Also output to console for immediate visibility
cat "$diag_file"
log "INFO" "Diagnostics stored in $diag_file"
}
print_summary() {
local host=$1
local status=$2
local last_stage=$(get_stage)
local last_service=$(get_last_service)
echo ""
echo "=========================================="
echo " DEPLOYMENT SUMMARY"
echo "=========================================="
echo "Host: $host"
echo "Status: $status"
echo "Last Stage: $last_stage"
[[ -n "$last_service" ]] && echo "Last Service: $last_service"
echo "Log File: $LOG_FILE"
echo "=========================================="
echo ""
}
export -f collect_diagnostics
export -f print_summary