halkyon/deploy/photon/serve.sh
Tizian 「ティツィアーン」 ba77248930
fix(deploy): the sidecars' downloads try again within the hour after a failed round
A failed BRouter segment or listing, a failed tile cut or an unwritable folder waited the whole refresh period, 30 days without routes or a map; they try again after an hour, doubling to a day. Photon's failed download backs off from a day to a week, and a dead Photon is noticed within a minute. The downloads' network is an ordinary bridge the three share, as the comments now say.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
2026-10-30 15:53:12 +01:00

58 lines
1.4 KiB
Shell

#!/bin/sh
# Serves Photon on the database in /data/current (Halkyon Train's ADR 0030, D50), once
# data.sh has brought one; and where data.sh has made a newer one (/data/next/ready),
# stops Photon, puts the new one in the old one's place and starts it again: a
# minute or two without search, once a month. Looked at every minute, which also
# starts a Photon that stopped (killed for memory) again. PHOTON_HEAP is Java's
# heap (6g).
set -eu
cd /data
heap=${PHOTON_HEAP:-6g}
pid=
start() {
java "-Xmx$heap" -jar /app/photon.jar serve -data-dir /data/current \
-listen-ip 0.0.0.0 -listen-port 2322 -max-results 20 &
pid=$!
}
stop() {
if [ -n "$pid" ]; then
kill "$pid" 2>/dev/null || true
wait "$pid" 2>/dev/null || true
pid=
fi
}
trap 'stop; exit 0' TERM INT
swap() {
[ -e next/ready ] || return 1
rm -f next/ready
rm -rf old
if [ -d current ]; then mv current old; fi
mkdir current
mv next/photon_data current/photon_data
mv next/fetched fetched
rm -rf old
}
while [ ! -d current/photon_data ] && ! swap; do
echo "No database yet; data.sh brings one."
sleep 600 &
wait $! || true
done
start
while :; do
sleep 60 &
wait $! || true
if [ -e next/ready ]; then
stop
swap
start
echo "Photon serves the new database."
elif ! kill -0 "$pid" 2>/dev/null; then
echo "Photon stopped; started again." >&2
start
fi
done