f/fundlab/server_watchdog.sh
Greg Pomerantz 81ef602d52 CEF app tab + server watchdog + full-universe verification batch
- Fund Lab tab: CEF tax-arb shortlist table (char actual-vs-model,
  discount, 5y return/vol, scenario hits, tenders, score) built from
  cef_character.json + cef_annual.json.
- fundlab/server_watchdog.sh: relaunches Streamlit on :8599 if the
  health endpoint stops answering (the old watchdog only covered the
  overnight screen and had exited).
- fundlab/cef_universe_run.py: resumable batch extending per-share
  verification to all 295 CEFs -> cef_annual_all.json.
2026-08-28 14:57:01 -04:00

32 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Keep the Streamlit app alive on port 8599.
#
# The server (or the machine) can drop it at any time, so every 5 minutes
# this checks whether something is answering on the port and, if not,
# relaunches it detached. Streamlit only hot-reloads app.py, so module
# changes need this relaunch (or a manual one) to take effect.
#
# Usage: setsid nohup fundlab/server_watchdog.sh </dev/null >>fundlab/server_watchdog.log 2>&1 &
set -u
cd "$(dirname "$0")/.."
PORT=8599
INTERVAL=300
alive() {
curl -s -o /dev/null --max-time 8 "http://127.0.0.1:${PORT}/_stcore/health" \
&& [ "$(curl -s --max-time 8 "http://127.0.0.1:${PORT}/_stcore/health")" = "ok" ]
}
while true; do
if ! alive; then
{ date "+%Y-%m-%d %H:%M:%S"
echo "server_watchdog: no answer on :${PORT} - relaunching"
} >> fundlab/server_watchdog.log
setsid nohup .venv/bin/streamlit run app.py \
--server.port "${PORT}" --server.headless true \
--browser.gatherUsageStats false >> fundlab/streamlit.log 2>&1 < /dev/null &
sleep 15
fi
sleep "${INTERVAL}"
done