#!/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