## Summary - Add Transmission BitTorrent daemon to k8s (torrent namespace) - Add Kiwix ZIM archive server to k8s (kiwix namespace) - NFS storage from sifaka for shared torrent/ZIM data - Torrent-sync sidecar in kiwix deployment to manage declarative ZIM list - ZIM-watcher CronJob to auto-restart kiwix when new archives appear - Remove transmission, transmission_metrics, and kiwix ansible roles from indri - Remove svc:kiwix from tailscale_serve defaults ## Key Decisions - Direct NFS mount for kiwix (no PVC) since it shares storage with transmission - Shell wrapper for kiwix-serve command (glob expansion) - Accept HTTP 409 as "ready" in torrent sync (transmission session ID mechanism) - Completed downloads stored in `/downloads/complete/` on sifaka ## Deployment and Testing - [x] Deployed transmission to k8s - [x] Verified transmission web UI at torrent.tail8d86e.ts.net - [x] Moved existing ZIM files to complete folder - [x] Deployed kiwix to k8s - [x] Verified kiwix web UI at kiwix.tail8d86e.ts.net - [x] Stopped old services on indri - [x] Cleared svc:kiwix from Tailscale serve on indri - [x] Updated zk documentation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Reviewed-on: https://forge.tail8d86e.ts.net/eblume/blumeops/pulls/39
68 lines
2.5 KiB
YAML
68 lines
2.5 KiB
YAML
---
|
|
apiVersion: v1
|
|
kind: ConfigMap
|
|
metadata:
|
|
name: zim-torrent-sync-script
|
|
namespace: kiwix
|
|
data:
|
|
sync-zim-torrents.sh: |
|
|
#!/bin/bash
|
|
# Sync ZIM torrents from kiwix ConfigMap to Transmission
|
|
# Runs as a sidecar in the kiwix deployment
|
|
set -euo pipefail
|
|
|
|
TORRENT_LIST="${TORRENT_LIST:-/config/torrents.txt}"
|
|
TRANSMISSION_HOST="${TRANSMISSION_HOST:-transmission.torrent.svc.cluster.local}"
|
|
TRANSMISSION_PORT="${TRANSMISSION_PORT:-9091}"
|
|
|
|
echo "Syncing ZIM torrents to transmission at ${TRANSMISSION_HOST}:${TRANSMISSION_PORT}"
|
|
|
|
# Wait for transmission to be ready
|
|
# Transmission RPC returns 409 on first request (to provide session ID), which is fine
|
|
echo "Waiting for Transmission RPC..."
|
|
max_attempts=30
|
|
attempt=0
|
|
until curl -s -o /dev/null -w "%{http_code}" "http://${TRANSMISSION_HOST}:${TRANSMISSION_PORT}/transmission/rpc" | grep -qE "^(200|409)$"; do
|
|
attempt=$((attempt + 1))
|
|
if [[ $attempt -ge $max_attempts ]]; then
|
|
echo "Transmission not ready after ${max_attempts} attempts, will retry next cycle"
|
|
exit 0 # Don't fail, just skip this sync
|
|
fi
|
|
sleep 10
|
|
done
|
|
echo "Transmission is ready"
|
|
|
|
# Get current torrents from transmission
|
|
# transmission-remote returns header + data + footer, extract just torrent names
|
|
current=$(transmission-remote "${TRANSMISSION_HOST}:${TRANSMISSION_PORT}" -l 2>/dev/null | \
|
|
tail -n +2 | head -n -1 | awk '{print $NF}' || true)
|
|
|
|
added=0
|
|
skipped=0
|
|
|
|
while IFS= read -r url || [[ -n "$url" ]]; do
|
|
# Skip empty lines and comments
|
|
[[ -z "$url" || "$url" =~ ^[[:space:]]*# ]] && continue
|
|
# Trim whitespace
|
|
url=$(echo "$url" | xargs)
|
|
[[ -z "$url" ]] && continue
|
|
|
|
# Extract base name from URL (remove .torrent extension)
|
|
basename=$(basename "$url" .torrent)
|
|
# Also try without .zim in case transmission reports it differently
|
|
basename_no_zim="${basename%.zim}"
|
|
|
|
# Check if already in transmission
|
|
if echo "$current" | grep -qF "$basename_no_zim"; then
|
|
((skipped++)) || true
|
|
else
|
|
if transmission-remote "${TRANSMISSION_HOST}:${TRANSMISSION_PORT}" -a "$url" 2>/dev/null; then
|
|
echo "Added: $basename"
|
|
((added++)) || true
|
|
else
|
|
echo "Warning: Failed to add $url" >&2
|
|
fi
|
|
fi
|
|
done < "$TORRENT_LIST"
|
|
|
|
echo "Sync complete: $added added, $skipped already present"
|