From 3b4687e1bbec31e910f8a143125ed36521bd67f2 Mon Sep 17 00:00:00 2001 From: "juvenal.diaz" Date: Tue, 6 Oct 2026 08:41:19 -0600 Subject: [PATCH] feat: add homelab post-migration doctor checks --- jeannie | 5 + lib/jeannie/commands.sh | 227 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 232 insertions(+) diff --git a/jeannie b/jeannie index 11afd6b..62c3566 100755 --- a/jeannie +++ b/jeannie @@ -133,6 +133,8 @@ Recovery And State Focused Doctors doctor-edge [--all|--details|--verbose|--json] Diagnose edge routing and public exposure. + doctor-homelab [--all|--details|--verbose|--json] + Run post-migration Pimox/Debian/edge checks. doctor-gitea [--all|--details|--verbose|--json] Diagnose Gitea local/public access. doctor-rpi [--all|--details|--verbose|--json] @@ -436,6 +438,9 @@ case "${1:-}" in doctor-edge) doctor_edge "${@:2}" ;; + doctor-homelab) + doctor_homelab "${@:2}" + ;; doctor-gitea) doctor_gitea "${@:2}" ;; diff --git a/lib/jeannie/commands.sh b/lib/jeannie/commands.sh index 1b7ffa9..8e661c3 100644 --- a/lib/jeannie/commands.sh +++ b/lib/jeannie/commands.sh @@ -904,6 +904,31 @@ status_kubernetes_deployment_ready() { kubectl --kubeconfig "${KUBECONFIG_PATH}" -n "${namespace}" rollout status "deployment/${deployment}" --timeout=5s >/dev/null } +status_kubernetes_statefulset_ready() { + local namespace="$1" + local statefulset="$2" + + kubectl --kubeconfig "${KUBECONFIG_PATH}" -n "${namespace}" rollout status "statefulset/${statefulset}" --timeout=5s >/dev/null +} + +status_kubernetes_deployment_image_not_bootstrap() { + local namespace="$1" + local deployment="$2" + local container="$3" + local image + + image="$(kubectl --kubeconfig "${KUBECONFIG_PATH}" -n "${namespace}" get deployment "${deployment}" \ + -o "jsonpath={.spec.template.spec.containers[?(@.name==\"${container}\")].image}" 2>/dev/null || true)" + if [[ -z "${image}" ]]; then + echo "could not read image for ${namespace}/deployment/${deployment} container ${container}" >&2 + return 1 + fi + if [[ "${image}" == *":bootstrap" ]]; then + echo "${namespace}/deployment/${deployment} still points to bootstrap image: ${image}" >&2 + return 1 + fi +} + status_no_problem_pods() { local rows @@ -1018,6 +1043,55 @@ status_registry_ok() { status_http_ok "http://${LAB_REGISTRY_ENDPOINT:-192.168.100.73:30500}/v2/" } +status_registry_from_pimox_workers() { + local spec_file="${REPO_ROOT}/.lab/pimox-workers.tsv" + local registry_endpoint="${LAB_REGISTRY_ENDPOINT:-192.168.100.73:30500}" + local failures=0 + local found=0 + local worker_key + local host + local user + local node_name + local key_path + local output + + if [[ "${LAB_CLUSTER_PROFILE:-debian}" != "pimox" ]]; then + echo "cluster profile is ${LAB_CLUSTER_PROFILE:-debian}; Pimox worker registry probe is not applicable" >&2 + return 1 + fi + if [[ ! -s "${spec_file}" ]]; then + echo "No Pimox worker spec found at ${spec_file}; run ./jeannie up or set LAB_CLUSTER_VAR_FILE." >&2 + return 1 + fi + + while IFS=$'\t' read -r worker_key host user node_name key_path; do + [[ -n "${worker_key}" && -n "${host}" && -n "${user}" && -n "${node_name}" && -n "${key_path}" ]] || continue + found=1 + if ! output="$(ssh -n -i "${key_path}" -o BatchMode=yes -o ConnectTimeout=8 -o StrictHostKeyChecking=accept-new "${user}@${host}" \ + "curl -fsS --connect-timeout 5 --max-time 10 'http://${registry_endpoint}/v2/' >/dev/null && echo ok" 2>&1)"; then + echo "${node_name}: ${output}" >&2 + failures=$((failures + 1)) + fi + done <"${spec_file}" + + if ((found == 0)); then + echo "No Pimox workers were listed in ${spec_file}." >&2 + return 1 + fi + + ((failures == 0)) +} + +status_dex_local_ok() { + status_http_reachable "http://127.0.0.1:${LAB_DEX_HTTP_PORT:-5556}/healthz" +} + +status_ollama_local_ok() { + local url="${LAB_OLLAMA_URL:-http://${LAB_DEBIAN_LAN_IP:-192.168.100.73}:11434}" + + status_http_ok "${url%/}/api/tags" +} + status_rpi_uptime_kuma_ok() { local rpi_host="${LAB_RPI_HOST:-${LAB_RASPBERRY_HOST:-192.168.100.89}}" local rpi_user="${LAB_RPI_USER:-${LAB_RASPBERRY_USER:-jv}}" @@ -1060,6 +1134,46 @@ status_pimox_workers_running() { ((failures == 0)) } +status_pimox_control_plane_running() { + local pimox_host="${LAB_PIMOX_HOST:-${TF_VAR_pimox_host:-192.168.100.80}}" + local pimox_user="${LAB_PIMOX_USER:-${TF_VAR_pimox_user:-jv}}" + local pimox_key="${LAB_PIMOX_SSH_KEY_PATH:-${TF_VAR_pimox_ssh_key_path:-/home/jv/.ssh/id_ed25519}}" + local qm_bin="${LAB_PIMOX_QM_BIN:-${TF_VAR_pimox_qm_bin:-/usr/sbin/qm}}" + local vmid="${LAB_CLUSTER_PIMOX_CONTROL_PLANE_VMID:-${LAB_PIMOX_CONTROL_PLANE_VMID:-}}" + + if [[ "${LAB_CLUSTER_PROFILE:-debian}" != "pimox" ]]; then + echo "cluster profile is ${LAB_CLUSTER_PROFILE:-debian}, not pimox" >&2 + return 1 + fi + if [[ -z "${vmid}" ]]; then + echo "Pimox control-plane VMID is not configured." >&2 + return 1 + fi + pimox_ssh "${pimox_host}" "${pimox_user}" "${pimox_key}" "sudo '${qm_bin}' status '${vmid}' | grep -q 'status: running'" +} + +status_cluster_profile_pimox() { + if [[ "${LAB_CLUSTER_PROFILE:-debian}" != "pimox" ]]; then + echo "active cluster profile is ${LAB_CLUSTER_PROFILE:-debian}; expected pimox for post-migration doctor" >&2 + return 1 + fi +} + +status_external_services_host_declared() { + if [[ -z "${LAB_SERVICES_HOST_LAN_IP:-${LAB_DEBIAN_LAN_IP:-}}" ]]; then + echo "external services host LAN IP is not resolved from homelab.yml" >&2 + return 1 + fi + if [[ -z "${LAB_GITEA_BACKEND_HOST:-${LAB_GITEA_TAILSCALE_IP:-${LAB_DEBIAN_TAILSCALE_IP:-}}}" ]]; then + echo "Gitea/edge backend host is not resolved from homelab.yml" >&2 + return 1 + fi + if [[ -z "${LAB_REGISTRY_ENDPOINT:-}" ]]; then + echo "registry endpoint is not resolved from homelab.yml" >&2 + return 1 + fi +} + status_cascade_report() { local failures=0 @@ -1808,6 +1922,119 @@ Known runbook: docs/runbooks/cluster-stop-start-failures.md EOF } +doctor_homelab() { + local failures=0 + + if ! report_ui_parse_args "$@"; then + return 1 + fi + require_debian_server "doctor-homelab" + + if [[ "${REPORT_UI_VERBOSE}" != "true" ]]; then + report_ui_begin + + report_ui_check fail "Architecture Boundary" "Pimox cluster profile" "LAB_CLUSTER_PROFILE=pimox ./jeannie up" "" "" status_cluster_profile_pimox || failures=$((failures + 1)) + report_ui_check fail "Architecture Boundary" "External services host resolved" "./jeannie cluster-profile" "" "" status_external_services_host_declared || failures=$((failures + 1)) + + report_ui_check fail "Pimox Runtime" "Pimox storage" "./jeannie doctor-cluster" "" "" check_pimox_storage || failures=$((failures + 1)) + report_ui_check fail "Pimox Runtime" "Control-plane VM running" "./jeannie start-cluster" "" "" status_pimox_control_plane_running || failures=$((failures + 1)) + report_ui_check fail "Pimox Runtime" "Worker VMs running" "./jeannie start-cluster" "" "" status_pimox_workers_running || failures=$((failures + 1)) + + report_ui_check fail "Kubernetes" "API ready" "./jeannie start-cluster" "" "" status_kubernetes_api_ok || failures=$((failures + 1)) + report_ui_check fail "Kubernetes" "Nodes Ready" "kubectl get nodes -o wide" "" "" status_kubernetes_nodes_ready || failures=$((failures + 1)) + report_ui_check fail "Kubernetes" "No problem pods" "kubectl get pods -A -o wide" "" "" status_no_problem_pods || failures=$((failures + 1)) + report_ui_check warn "Kubernetes" "Recent deployments healthy" "kubectl get deployments -A" "" "" status_recent_deployments + report_ui_check warn "Kubernetes" "Node pressure" "kubectl describe nodes" "" "" status_node_pressure + + report_ui_check fail "Platform" "Traefik deployment" "./jeannie platform" "" "" status_kubernetes_deployment_ready traefik traefik || failures=$((failures + 1)) + report_ui_check fail "Platform" "Traefik LoadBalancer HTTP" "./jeannie edge apply" "" "" status_http_reachable "http://${LAB_TRAEFIK_LB_IP:?LAB_TRAEFIK_LB_IP is required from homelab.yml}/" || failures=$((failures + 1)) + report_ui_check fail "Platform" "Argo CD server" "./jeannie platform" "" "" status_kubernetes_deployment_ready argocd argocd-server || failures=$((failures + 1)) + report_ui_check fail "Platform" "Grafana StatefulSet" "./jeannie platform" "" "" status_kubernetes_statefulset_ready monitoring prometheus-stack-grafana || failures=$((failures + 1)) + + report_ui_check fail "Applications" "Website deployment" "./jeannie apps" "" "" status_kubernetes_deployment_ready website-production php-website-deployment || failures=$((failures + 1)) + report_ui_check fail "Applications" "Demos deployment" "./jeannie apps" "" "" status_kubernetes_deployment_ready demos-static demos-static || failures=$((failures + 1)) + report_ui_check fail "Applications" "Website image not bootstrap" "./jeannie apps" "" "" status_kubernetes_deployment_image_not_bootstrap website-production php-website-deployment php-app || failures=$((failures + 1)) + report_ui_check fail "Applications" "Demos image not bootstrap" "./jeannie apps" "" "" status_kubernetes_deployment_image_not_bootstrap demos-static demos-static demos-static || failures=$((failures + 1)) + report_ui_check fail "Applications" "n8n deployment" "./jeannie apps" "" "" status_kubernetes_deployment_ready n8n n8n || failures=$((failures + 1)) + + report_ui_check fail "Registry" "Registry HTTP" "./jeannie apps" "" "" status_registry_ok || failures=$((failures + 1)) + report_ui_check fail "Registry" "Registry reachable from Pimox workers" "./jeannie apps" "" "" status_registry_from_pimox_workers || failures=$((failures + 1)) + + report_ui_check fail "Debian Services" "Docker service" "sudo systemctl restart docker" "" "" check_systemd_active docker || failures=$((failures + 1)) + report_ui_check fail "Debian Services" "Gitea container" "./jeannie deploy-gitea" "" "" status_container_running "${GITEA_CONTAINER_NAME:-homelab-gitea}" || failures=$((failures + 1)) + report_ui_check fail "Debian Services" "Gitea local HTTP" "./jeannie deploy-gitea" "" "" status_http_ok "http://127.0.0.1:${LAB_GITEA_HTTP_PORT:-3000}/" || failures=$((failures + 1)) + report_ui_check fail "Debian Services" "Dex local HTTP" "./jeannie deploy-dex" "" "" status_dex_local_ok || failures=$((failures + 1)) + report_ui_check warn "Debian Services" "Ollama API" "./jeannie ollama-setup" "" "" status_ollama_local_ok + report_ui_check warn "Debian Services" "Gitea runner service" "./jeannie install-gitea-runner" "" "" check_systemd_active homelab-gitea-runner + + report_ui_check warn "RPi DNS" "Pi-hole DNS" "./jeannie rpi-services" "" "" check_pihole_dns_query + report_ui_check warn "RPi DNS" "Uptime Kuma HTTP" "./jeannie rpi-services" "" "" status_rpi_uptime_kuma_ok + + report_ui_check fail "Edge/Public" "OCI edge SSH" "./jeannie edge apply" "" "" check_edge_ssh || failures=$((failures + 1)) + report_ui_check fail "Edge/Public" "Edge to Traefik backend" "./jeannie edge apply" "" "" check_edge_traefik_backend || failures=$((failures + 1)) + report_ui_check fail "Edge/Public" "Website public URL" "./jeannie doctor-edge" "" "" status_http_ok "${LAB_PUBLIC_URL:?LAB_PUBLIC_URL is required from homelab.yml}/" || failures=$((failures + 1)) + report_ui_check fail "Edge/Public" "Gitea public URL" "./jeannie doctor-gitea" "" "" status_gitea_public_ok || failures=$((failures + 1)) + report_ui_check fail "Edge/Public" "Grafana public URL" "./jeannie platform" "" "" status_http_ok "https://grafana.${LAB_DOMAIN:?LAB_DOMAIN is required from homelab.yml}/login" || failures=$((failures + 1)) + report_ui_check fail "Edge/Public" "Argo CD public URL" "./jeannie platform" "" "" status_http_reachable "https://argocd.${LAB_DOMAIN:?LAB_DOMAIN is required from homelab.yml}/" || failures=$((failures + 1)) + report_ui_check fail "Edge/Public" "Demos public URL" "./jeannie apps" "" "" status_http_ok "https://demos.${LAB_DOMAIN:?LAB_DOMAIN is required from homelab.yml}/" || failures=$((failures + 1)) + report_ui_check fail "Edge/Public" "Dex public URL" "./jeannie deploy-dex" "" "" status_http_reachable "${LAB_DEX_PUBLIC_URL:-https://auth.${LAB_DOMAIN:?LAB_DOMAIN is required from homelab.yml}/}" || failures=$((failures + 1)) + + report_ui_check warn "Operations" "Backup freshness" "./jeannie backup" "" "" backup_status + report_ui_check warn "Operations" "Disk usage" "df -h / /data" "" "" status_disk_pressure + report_ui_check warn "Operations" "Pod restart pressure" "kubectl get pods -A" "" "" status_pod_restart_pressure + report_ui_check warn "Operations" "Traefik 5xx/404 signals" "kubectl -n traefik logs -l app.kubernetes.io/name=traefik --since=30m" "" "" status_traefik_error_rates + + report_ui_render "Post-Migration Homelab Doctor" + report_ui_cleanup + return "${failures}" + fi + + status_section "Post-Migration Homelab Doctor" + cluster_profile_report + + status_section "Pimox Kubernetes" + status_run "pimox storage" check_pimox_storage + status_run "control-plane VM running" status_pimox_control_plane_running + status_pimox_workers + status_kubernetes + + status_section "Platform And Apps" + status_run "registry HTTP" status_registry_ok + status_run "registry from Pimox workers" status_registry_from_pimox_workers + status_run "traefik deployment" kubectl --kubeconfig "${KUBECONFIG_PATH}" -n traefik get deploy,svc,pod -o wide + status_run "website image" kubectl --kubeconfig "${KUBECONFIG_PATH}" -n website-production get deployment php-website-deployment -o jsonpath='{.spec.template.spec.containers[0].image}{"\n"}' + status_run "demos image" kubectl --kubeconfig "${KUBECONFIG_PATH}" -n demos-static get deployment demos-static -o jsonpath='{.spec.template.spec.containers[0].image}{"\n"}' + + status_section "Debian External Services" + status_systemd_units docker tailscaled homelab-gitea-runner + status_compose_stack "gitea" "/data/homelab-gitea" + status_compose_stack "dex" "${LAB_DEX_INSTALL_DIR:-/data/homelab-dex}" + status_http "gitea local" "http://127.0.0.1:${LAB_GITEA_HTTP_PORT:-3000}/" + status_http "dex local" "http://127.0.0.1:${LAB_DEX_HTTP_PORT:-5556}/healthz" + status_http "ollama" "${LAB_OLLAMA_URL:-http://${LAB_DEBIAN_LAN_IP:-192.168.100.73}:11434}/api/tags" + + status_section "Edge And Public URLs" + status_http "traefik lb" "http://${LAB_TRAEFIK_LB_IP:?LAB_TRAEFIK_LB_IP is required from homelab.yml}/" + status_http "website public" "${LAB_PUBLIC_URL:?LAB_PUBLIC_URL is required from homelab.yml}/" + status_http "gitea public" "${LAB_GITEA_ROOT_URL:-${LAB_PUBLIC_URL:?LAB_PUBLIC_URL is required from homelab.yml}/git/}" + status_http "grafana public" "https://grafana.${LAB_DOMAIN:?LAB_DOMAIN is required from homelab.yml}/login" + status_http "argocd public" "https://argocd.${LAB_DOMAIN:?LAB_DOMAIN is required from homelab.yml}/" + status_http "demos public" "https://demos.${LAB_DOMAIN:?LAB_DOMAIN is required from homelab.yml}/" + status_http "dex public" "${LAB_DEX_PUBLIC_URL:-https://auth.${LAB_DOMAIN:?LAB_DOMAIN is required from homelab.yml}/}" + + status_section "Operations" + backup_status || true + + cat <<'EOF' + +Next steps: +- If a Kubernetes check fails, run ./jeannie doctor-cluster --verbose. +- If a public URL fails but local backends pass, run ./jeannie doctor-edge --verbose. +- If a registry/image check fails, run LAB_CLUSTER_PROFILE=pimox ./jeannie apps. +- If Debian service checks fail, rerun the matching deploy command rather than moving the service into Kubernetes. +EOF +} + nuke() { local target local target_host