From c4080976bce3eb4fcad2ebfb8c142e44701c7310 Mon Sep 17 00:00:00 2001 From: dev Date: Mon, 12 Oct 2026 22:26:33 +0530 Subject: [PATCH] Deploy artifacts: Termux service scripts plus tunnel config deploy/termux-{start,stop,status}.sh manage the release binary on the tablet; deploy/cloudflared-whaleprep.yml is the dedicated tunnel config for whaleprep.oiupoyt.space. README gains a deploy section. --- README.md | 18 ++++++++++++++++++ deploy/cloudflared-whaleprep.yml | 14 ++++++++++++++ deploy/termux-start.sh | 29 +++++++++++++++++++++++++++++ deploy/termux-status.sh | 10 ++++++++++ deploy/termux-stop.sh | 4 ++++ 5 files changed, 75 insertions(+) create mode 100644 deploy/cloudflared-whaleprep.yml create mode 100755 deploy/termux-start.sh create mode 100755 deploy/termux-status.sh create mode 100755 deploy/termux-stop.sh diff --git a/README.md b/README.md index f07a2f9..b19c2cc 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,24 @@ Recommended floor: **1 vCPU / 512 MB RAM / 5 GB disk**. Comfortable headroom: **1 vCPU / 1 GB RAM / 10 GB SSD**. No Postgres, no Redis, no object storage — one static binary plus one SQLite file. +## Deploy (Termux + Cloudflare Tunnel) + +The live site runs on an ARM tablet via Termux behind a dedicated tunnel: + + # on the host + pkg install rust sqlite python git + git clone https://git.oiupoyt.space/oiupoyt/whaleprep.git + cd whaleprep && cargo build --release + ./deploy/termux-start.sh + python3 scripts/import_examgoal.py whaleprep.db # 9,813 real PYQs + + # tunnel (once): cloudflared tunnel create whaleprep, point the CNAME at it + cloudflared tunnel --config ~/.cloudflared/whaleprep.yml \ + run ffc0df8c-0978-4b54-93a1-57c64fa1464c + +See [deploy/](deploy/) for the service scripts and tunnel config. +Live at: https://whaleprep.oiupoyt.space + ## Tests cargo test diff --git a/deploy/cloudflared-whaleprep.yml b/deploy/cloudflared-whaleprep.yml new file mode 100644 index 0000000..4e6729a --- /dev/null +++ b/deploy/cloudflared-whaleprep.yml @@ -0,0 +1,14 @@ +# Dedicated tunnel config for whaleprep.oiupoyt.space. +# On the Termux host this lives at ~/.cloudflared/whaleprep.yml with the +# credentials-file path adjusted to that machine's home. +# Create once: cloudflared tunnel create whaleprep +# DNS once: cloudflared tunnel --config whaleprep.yml route dns --overwrite-dns whaleprep.oiupoyt.space +# Run: cloudflared tunnel --config whaleprep.yml run +tunnel: FFC0DF8C-0978-4B54-93A1-57C64FA1464C +credentials-file: ~/.cloudflared/ffc0df8c-0978-4b54-93a1-57c64fa1464c.json +protocol: http2 + +ingress: + - hostname: whaleprep.oiupoyt.space + service: http://localhost:8222 + - service: http_status:404 diff --git a/deploy/termux-start.sh b/deploy/termux-start.sh new file mode 100755 index 0000000..61fa873 --- /dev/null +++ b/deploy/termux-start.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +# Start WhalePrep on Termux (SQLite, port 8222) in background. +# Usage: ./deploy/termux-start.sh (run from repo root) +cd "$(dirname "$0")/.." +PID_FILE="./whaleprep.pid" +LOG_FILE="./whaleprep.log" +DB_FILE="./whaleprep.db" +PORT=8222 +if [ -f "$PID_FILE" ]; then + PID=$(cat "$PID_FILE") + if kill -0 "$PID" 2>/dev/null; then + echo "WhalePrep is already running (PID: $PID)" + exit 0 + else + rm -f "$PID_FILE" + fi +fi +[ -x ./target/release/whaleprep ] || { echo "missing ./target/release/whaleprep — run: cargo build --release"; exit 1; } +echo "Starting WhalePrep on :$PORT (db $DB_FILE)..." +PYQ_DB="$DB_FILE" PYQ_ADDR="127.0.0.1:$PORT" RUST_LOG=info nohup ./target/release/whaleprep > "$LOG_FILE" 2>&1 & +NEW_PID=$! +echo $NEW_PID > "$PID_FILE" +disown $NEW_PID 2>/dev/null || true +sleep 2 +if kill -0 "$NEW_PID" 2>/dev/null; then + echo "WhalePrep started (PID: $NEW_PID) -> http://localhost:$PORT" +else + echo "FAILED — tail $LOG_FILE:"; tail -5 "$LOG_FILE" +fi diff --git a/deploy/termux-status.sh b/deploy/termux-status.sh new file mode 100755 index 0000000..b79fa8d --- /dev/null +++ b/deploy/termux-status.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +# WhalePrep status + health ping. Usage: ./deploy/termux-status.sh +cd "$(dirname "$0")/.." +if [ -f ./whaleprep.pid ] && kill -0 "$(cat ./whaleprep.pid)" 2>/dev/null; then + PID=$(cat ./whaleprep.pid) + echo "RUNNING (PID $PID, RSS $(( $(ps -o rss= -p $PID 2>/dev/null || echo 0) / 1024 )) MB)" + curl -s -o /dev/null -w "health=%{http_code}\n" http://127.0.0.1:8222/ 2>&1 || echo "port not responding" +else + echo "NOT running" +fi diff --git a/deploy/termux-stop.sh b/deploy/termux-stop.sh new file mode 100755 index 0000000..3d20a59 --- /dev/null +++ b/deploy/termux-stop.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +# Stop WhalePrep. Usage: ./deploy/termux-stop.sh (run from repo root) +cd "$(dirname "$0")/.." +[ -f ./whaleprep.pid ] && PID=$(cat ./whaleprep.pid) && kill "$PID" 2>/dev/null && rm -f ./whaleprep.pid && echo "stopped $PID" || echo "not running"