harb/scripts/watch-kraiken-lib.sh
johba a29ca1a26a Harden kraiken-lib watch loop and confirm host-built dist propagation (#38)
- expand scripts/watch-kraiken-lib.sh to watch atomic rename events, validate required tools, and gracefully restart only the containers that mount kraiken-
  lib/dist
  - verify the host-built dist is mounted read-only inside each service and observe live rebuild + restart behavior under inotify
  - run the local podman stack, exercise the watcher by editing kraiken-lib/src/helpers.ts, and confirm GraphQL responds through Caddy after restarts

resolves #33

Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: johba <johba@harb.eth>
Reviewed-on: https://codeberg.org/johba/harb/pulls/38
2025-10-02 14:33:59 +02:00

56 lines
1.3 KiB
Bash
Executable file

#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
WATCH_DIR="$ROOT_DIR/kraiken-lib/src"
SERVICES=(harb_ponder_1 harb_webapp_1 harb_landing_1 harb_txn-bot_1)
if ! command -v inotifywait >/dev/null 2>&1; then
echo "Error: inotifywait not found. Install inotify-tools." >&2
exit 1
fi
if ! command -v podman >/dev/null 2>&1; then
echo "Error: podman not found on PATH." >&2
exit 1
fi
cd "$ROOT_DIR"
restart_services() {
local missing=0
local running
mapfile -t running < <(podman ps --format '{{.Names}}')
for service in "${SERVICES[@]}"; do
local found=1
for name in "${running[@]}"; do
if [[ "$name" == "$service" ]]; then
found=0
break
fi
done
if (( found != 0 )); then
echo "Warning: $service not running; skipping restart" >&2
missing=1
continue
fi
if ! podman restart "$service" >/dev/null; then
echo "Warning: failed to restart $service" >&2
missing=1
fi
done
if [[ $missing -eq 0 ]]; then
echo "Services restarted"
fi
}
inotifywait -m -r -e close_write,create,delete,moved_to,moved_from "$WATCH_DIR" |
while read -r _directory _events filename; do
echo "kraiken-lib changed: $filename"
./scripts/build-kraiken-lib.sh
restart_services || true
done