interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / infra / spark / edge-mirror.sh

26 lines · 1397 bytes Raw Blame History
1#!/bin/sh
2# spark/edge-mirror.sh: keep the Spark front door's site folders equal to the hub Pi's.
3# The publishers (aienos.com deploy, interplane.io sync-to-hub, hive-publish, stats collect.sh)
4# still write to the Pi; this pulls each folder to the same path on the Spark, one way only.
5# Runs from the spark user timer edge-mirror.timer and, for interplane.io publishes, from
6# edge-mirror-onchange.service. One run at a time (lock below). Never writes to the Pi.
7# Host tools: rsync 3.2.7 + OpenSSH (Spark), rsync on the Pi. Omega replacement: publishers
8# write straight to the Spark once the Pi is retired as a web host (then this script goes).
9set -u
10HUB=${HUB:-hub}
11LOG=${EDGE_MIRROR_LOG:-$HOME/.local/state/edge-mirror.log}
12mkdir -p "$(dirname "$LOG")"
13# Wait (not skip) when the other runner holds the lock, so a change seen during its run is still pulled.
14exec 9>>"${EDGE_MIRROR_LOCK:-${XDG_RUNTIME_DIR:-/tmp}/edge-mirror.lock}"
15flock 9
16rc=0
17for d in aienos.com aienos-code aienos-hive aienos-stats interplane.io replicate si; do
18 if ! timeout 900 rsync -a -H --delete --chmod=a+rX --timeout=120 \
19 -e 'ssh -o BatchMode=yes -o ConnectTimeout=60' \
20 --rsync-path='nice -n 15 ionice -c3 rsync' \
21 "$HUB:/var/www/$d/" "/var/www/$d/" >>"$LOG" 2>&1; then
22 echo "$(date -u +%FT%TZ) FAIL $d" >>"$LOG"; rc=1
23 fi
24done
25echo "$(date -u +%FT%TZ) done rc=$rc" >>"$LOG"
26exit $rc