#!/bin/bash # Keeps OmniRoute's SQLite state alive across Space restarts/sleeps by # syncing /app/data to a private HuggingFace Dataset repo. # # Required Space secrets (Settings → Variables and secrets): # HF_TOKEN — a HF token with WRITE access to the dataset below # HF_STATE_DATASET — e.g. "your-username/omniroute-state" (make it PRIVATE — # it will contain encrypted provider keys) # JWT_SECRET, API_KEY_SECRET, STORAGE_ENCRYPTION_KEY, INITIAL_PASSWORD # — same as any other OmniRoute deployment set -u DATA_DIR=/app/data mkdir -p "$DATA_DIR" : "${HF_TOKEN:?Set HF_TOKEN as a Space secret}" : "${HF_STATE_DATASET:?Set HF_STATE_DATASET as a Space secret, e.g. you/omniroute-state}" echo "[sync] attempting to restore prior state from ${HF_STATE_DATASET}..." python3 - </dev/null; exit 0' SIGTERM SIGINT # Hand off to the image's normal server process (Next.js standalone server — # this is the base image's own default CMD, reproduced here explicitly # since our CMD override replaced it). node dev/run-standalone.mjs & SERVER_PID=$! wait "$SERVER_PID"