51 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
# start.sh — Launch fine-tuner with SSH tunnel to Erik's PostgreSQL
#
# Usage:
# ./scripts/start.sh # run fine-tuner
# ./scripts/start.sh --dry-run # dry run (no training)
# ./scripts/start.sh --status # show status only
set -euo pipefail
cd "$(dirname "$0")/.."
TUNNEL_PORT=5434
SSH_HOST="erik"
REMOTE_PG_PORT=5432
echo "[start.sh] Opening SSH tunnel to Erik:${REMOTE_PG_PORT} → localhost:${TUNNEL_PORT}"
# Kill any existing tunnel on that port
pkill -f "ssh.*${TUNNEL_PORT}:localhost:${REMOTE_PG_PORT}" 2>/dev/null || true
sleep 1
# Open tunnel in background
ssh -N -L "${TUNNEL_PORT}:localhost:${REMOTE_PG_PORT}" "${SSH_HOST}" &
TUNNEL_PID=$!
# Wait for tunnel to be ready
sleep 3
echo "[start.sh] Tunnel established (PID: ${TUNNEL_PID})"
# Cleanup tunnel on exit
cleanup() {
echo "[start.sh] Closing SSH tunnel (PID: ${TUNNEL_PID})"
kill "${TUNNEL_PID}" 2>/dev/null || true
}
trap cleanup EXIT
# Run fine-tuner with tunnel DB URL
# Fine-tuner reads FT_DB_URL (see src/main.py load_config)
export FT_DB_URL="postgresql://llm:llm_secure_2026@localhost:${TUNNEL_PORT}/llm_gateway"
export FT_GATEWAY_URL="https://llm-gateway.context-x.org"
export FT_OLLAMA_URL="http://localhost:11434"
echo "[start.sh] Starting fine-tuner..."
# Route --status / --dry-run / --task-type / --general / --dpo to manual_trigger.py
# No args = daemon loop via python3 -m src.main
if [ "$#" -eq 0 ]; then
python3 -m src.main
else
python3 scripts/manual_trigger.py "$@"
fi