20260622 恢复Routinator inter-RP监控
This commit is contained in:
73
scripts/inter_rp/sync_routinator_from_remote231.sh
Executable file
73
scripts/inter_rp/sync_routinator_from_remote231.sh
Executable file
@@ -0,0 +1,73 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
REMOTE231="${REMOTE231:-root@47.251.127.231}"
|
||||
REMOTE_ROOT="${REMOTE_ROOT:-/var/lib/inter-rp-runners}"
|
||||
PEER_ROOT="${PEER_ROOT:-/root/ours-rp-continuous/portable-soak/inter-rp-peers}"
|
||||
SYNC_INTERVAL_SECS="${SYNC_INTERVAL_SECS:-60}"
|
||||
MAX_SYNCS="${MAX_SYNCS:--1}"
|
||||
LOG_PREFIX="[inter-rp-sync]"
|
||||
mkdir -p "$PEER_ROOT/routinator"
|
||||
write_status() {
|
||||
local success="$1"
|
||||
local message="$2"
|
||||
env SYNC_SUCCESS="$success" SYNC_MESSAGE="$message" SYNC_REMOTE="$REMOTE231" SYNC_REMOTE_ROOT="$REMOTE_ROOT" python3 - "$PEER_ROOT/sync-status.json" <<'PY'
|
||||
import datetime, json, os, socket, sys
|
||||
path = sys.argv[1]
|
||||
payload = {
|
||||
"schemaVersion": 1,
|
||||
"success": os.environ["SYNC_SUCCESS"] == "true",
|
||||
"lastSyncAtRfc3339Utc": datetime.datetime.now(datetime.UTC).replace(microsecond=0).isoformat().replace("+00:00", "Z"),
|
||||
"remoteHost": os.environ["SYNC_REMOTE"],
|
||||
"remoteRoot": os.environ["SYNC_REMOTE_ROOT"],
|
||||
"localHost": socket.gethostname(),
|
||||
"message": os.environ["SYNC_MESSAGE"],
|
||||
}
|
||||
with open(path, "w", encoding="utf-8") as handle:
|
||||
json.dump(payload, handle, indent=2)
|
||||
handle.write("\n")
|
||||
PY
|
||||
}
|
||||
sync_once() {
|
||||
local tmp="$PEER_ROOT/.sync-routinator-$$"
|
||||
rm -rf "$tmp"
|
||||
mkdir -p "$tmp"
|
||||
if ! rsync -aL --delete \
|
||||
--include='run-meta.json' \
|
||||
--include='result.ccr' \
|
||||
--include='vrps.csv' \
|
||||
--include='vaps.csv' \
|
||||
--include='stdout.log' \
|
||||
--include='stderr.log' \
|
||||
--exclude='*' \
|
||||
"$REMOTE231:$REMOTE_ROOT/routinator/latest/" "$tmp/latest/"; then
|
||||
rm -rf "$tmp"
|
||||
return 1
|
||||
fi
|
||||
if [[ ! -f "$tmp/latest/run-meta.json" ]]; then
|
||||
rm -rf "$tmp"
|
||||
return 2
|
||||
fi
|
||||
rm -rf "$PEER_ROOT/routinator/latest.next" "$PEER_ROOT/routinator/latest.prev"
|
||||
mv "$tmp/latest" "$PEER_ROOT/routinator/latest.next"
|
||||
if [[ -e "$PEER_ROOT/routinator/latest" ]]; then
|
||||
mv "$PEER_ROOT/routinator/latest" "$PEER_ROOT/routinator/latest.prev"
|
||||
fi
|
||||
mv "$PEER_ROOT/routinator/latest.next" "$PEER_ROOT/routinator/latest"
|
||||
rm -rf "$PEER_ROOT/routinator/latest.prev" "$tmp"
|
||||
}
|
||||
completed=0
|
||||
while true; do
|
||||
if sync_once; then
|
||||
echo "$LOG_PREFIX $(date -u +%Y-%m-%dT%H:%M:%SZ) ok"
|
||||
write_status true "ok"
|
||||
else
|
||||
code=$?
|
||||
echo "$LOG_PREFIX $(date -u +%Y-%m-%dT%H:%M:%SZ) sync failed code=$code" >&2
|
||||
write_status false "routinator rsync failed code=$code"
|
||||
fi
|
||||
completed=$((completed + 1))
|
||||
if [[ "$MAX_SYNCS" =~ ^[0-9]+$ ]] && (( completed >= MAX_SYNCS )); then
|
||||
break
|
||||
fi
|
||||
sleep "$SYNC_INTERVAL_SECS"
|
||||
done
|
||||
Reference in New Issue
Block a user