Files
seal-use/host-infra/infra-healthcheck.sh
gitea 7fe5cae62c Rename wsl-infra to host-infra
The directory covers cross-host operations (mac15, mac13, WSL, Aliyun), not just WSL. Update the backup script's archive paths, README commands, and AGENTS/README references; the remote ops-backups directory name stays unchanged.
2026-11-19 16:14:15 +08:00

75 lines
3.5 KiB
Bash
Executable File

#!/usr/bin/env bash
set -uo pipefail
# Run from mac15. This is read-only and emits one JSON report.
SSH_OPTS=(-o BatchMode=yes -o ConnectTimeout=8)
json_result() {
local name="$1" status="$2" detail="$3"
jq -n --arg name "$name" --arg status "$status" --arg detail "$detail" \
'{name:$name,status:$status,detail:$detail}'
}
run_ssh() {
local host="$1" command="$2" output
if output=$(ssh "${SSH_OPTS[@]}" "$host" "$command" 2>&1); then
printf 'ok\t%s' "$(tr '\n' ' ' <<< "$output")"
else
printf 'fail\t%s' "$(tr '\n' ' ' <<< "$output")"
fi
}
check_ssh() {
local name="$1" host="$2" command="$3" result status detail
result=$(run_ssh "$host" "$command")
status=${result%%$'\t'*}
detail=${result#*$'\t'}
json_result "$name" "$status" "$detail"
}
check_local_proxy() {
local code
code=$(curl -sS -o /dev/null --proxy http://127.0.0.1:7897 \
--connect-timeout 5 --max-time 15 -w '%{http_code}' https://github.com 2>/dev/null || true)
[ "$code" = "200" ] && json_result mac15_proxy ok "github_http=$code" || json_result mac15_proxy fail "github_http=$code"
}
check_local_wsl_tailscale() {
local output
if output=$(tailscale ping --c 1 wsl-dev 2>&1); then
json_result mac15_wsl_tailscale ok "$(tr '\n' ' ' <<< "$output")"
else
json_result mac15_wsl_tailscale fail "$(tr '\n' ' ' <<< "$output")"
fi
}
check_local_wsl_ssh() {
local output
if output=$(ssh "${SSH_OPTS[@]}" wsl-dev 'printf "host=%s tailscale_ip=%s" "$(hostname)" "$(tailscale ip -4)"' 2>&1); then
json_result mac15_wsl_ssh ok "$(tr '\n' ' ' <<< "$output")"
else
json_result mac15_wsl_ssh fail "$(tr '\n' ' ' <<< "$output")"
fi
}
results=(
"$(check_local_proxy)"
"$(check_local_wsl_tailscale)"
"$(check_local_wsl_ssh)"
"$(check_ssh wsl_tailscale wsl-dev 'tailscale ip -4')"
"$(check_ssh wsl_frp wsl-dev 'docker inspect -f "{{.State.Status}}" frpc-wsl-gateway')"
"$(check_ssh wsl_mihomo wsl-dev 'systemctl is-active --quiet mihomo.service && ss -ltn | grep -q "127.0.0.1:7897" && printf "service=active,listener=127.0.0.1:7897"')"
"$(check_ssh wsl_release_sync_timer wsl-dev 'test "$(systemctl is-enabled seal-use-release-sync.timer 2>/dev/null)" = enabled && test "$(systemctl is-active seal-use-release-sync.timer 2>/dev/null)" = active && printf "timer=enabled,active"')"
"$(check_ssh wsl_release_sync_recent_success wsl-dev 'journalctl -q -u seal-use-release-sync.service --since "24 hours ago" --no-pager | grep -E "fully synchronized to Gitea" | tail -1')"
"$(check_ssh wsl_gitea wsl-dev 'curl -sS -o /dev/null -w "gitea_http=%{http_code}" http://127.0.0.1:3001/api/v1/version')"
"$(check_ssh wsl_github_proxy wsl-dev 'NO_PROXY= no_proxy= curl -sS -o /dev/null --proxy http://127.0.0.1:7897 --connect-timeout 8 --max-time 15 -w "github_http=%{http_code}" https://github.com 2>/dev/null')"
"$(check_ssh windows_tailscale windows '"C:\Program Files\Tailscale\tailscale.exe" ip -4')"
"$(check_ssh windows_wifi windows 'netsh wlan show interfaces | findstr /C:"SSID"')"
"$(check_ssh mac13_proxy mac13 'curl -sS -o /dev/null --proxy http://127.0.0.1:7897 --connect-timeout 5 --max-time 15 -w "github_http=%{http_code}" https://github.com 2>/dev/null')"
"$(check_ssh aliyun_frps aliyun 'docker inspect -f "{{.State.Status}}" frps')"
"$(check_ssh aliyun_gitea aliyun 'curl -sS -o /dev/null -w "gitea_public_http=%{http_code}" https://git.ying-qing.cn/api/v1/version')"
)
printf '%s\n' "${results[@]}" | jq -s --arg generatedAt "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
'{generatedAt:$generatedAt,checks:.}'