← back to Carnegie Reprice
supervise.sh.DISABLED
28 lines
#!/bin/bash
# supervise.sh — keep the sharded Carnegie rollout workers alive until the ledger is complete.
# Fully detached; auto-restarts a shard worker if it dies. Stops when 0 SKUs remain or HALT flag set.
cd "$(dirname "$0")" || exit 1
SHARDS=3
NODE=$(command -v node)
log(){ echo "[$(date -u +%H:%M:%S)] $*" >> supervise.log; }
log "supervisor start (pid $$), $SHARDS shards"
while true; do
if [ -f rebuild-HALTED.flag ]; then log "HALT flag present — supervisor exiting"; exit 0; fi
remaining=$("$NODE" rebuild-line.mjs --status 2>/dev/null | head -1 | sed -E 's/.* ([0-9]+) remaining.*/\1/')
if [ "$remaining" = "0" ]; then log "0 remaining — rollout complete, supervisor exiting"; exit 0; fi
for n in $(seq 1 $SHARDS); do
pidfile="worker-$n.pid"
alive=0
if [ -f "$pidfile" ] && kill -0 "$(cat "$pidfile")" 2>/dev/null; then alive=1; fi
if [ $alive -eq 0 ]; then
nohup "$NODE" rebuild-line.mjs --shard "$n/$SHARDS" >> "rebuild-shard-$n.log" 2>&1 &
echo $! > "$pidfile"
log "started shard $n/$SHARDS pid $! (remaining $remaining)"
sleep 3
fi
done
sleep 30
done