OmniRoute / entrypoint.sh
alpgul's picture
Update entrypoint.sh (#1)
f057977
Raw
History Blame Contribute Delete
1.77 kB
#!/bin/bash
# --- KATİ KURALLAR (Strict Mode) ---
set -euo pipefail
# ======================= Yapılandırma =======================
export DB_DIR="/app/data"
export REPO_ID="${REPO_ID:-alpgul/omniroute-storage}"
export HF_HOME="/tmp/.cache/huggingface"
# ===========================================================
echo "[$(date +'%T')] --- OmniRoute /app/data Yedekleme ---"
# 1. Dizin Kontrolü
mkdir -p "$DB_DIR"
# 2. HF Token Denetimi
if [[ -z "${HF_TOKEN:-}" ]]; then
echo "[HATA] HF_TOKEN eksik! Settings > Secrets kısmından ekleyin."
exit 1
fi
# 3. Restore (Dosyaları Hub'dan İndir)
echo "[Restore] Hub'dan dosyalar kontrol ediliyor..."
python3 -c "
from huggingface_hub import hf_hub_download
files = ['storage.sqlite', 'storage.sqlite-shm', 'storage.sqlite-wal']
for f in files:
try:
hf_hub_download(
repo_id='${REPO_ID}',
filename=f,
repo_type='dataset',
local_dir='${DB_DIR}',
token='${HF_TOKEN}'
)
print(f'√ {f} indirildi.')
except Exception as e:
print(f'- {f} bulunamadı, atlanıyor.')
" || true
# 4. CommitScheduler ile Arka Plan Senkronizasyonu
echo "[Scheduler] Otomatik senkronizasyon başlatılıyor..."
python3 -c "
import time
from huggingface_hub import CommitScheduler
scheduler = CommitScheduler(
repo_id='${REPO_ID}',
repo_type='dataset',
folder_path='${DB_DIR}',
allow_patterns=['*.sqlite', '*.sqlite-shm', '*.sqlite-wal'],
every=5,
squash_history=True,
token='${HF_TOKEN}',
)
print('[Scheduler] Aktif: her 5 dakikada bir sync, squash_history=True')
while True:
time.sleep(60)
" &
# 5. Uygulamayı Başlat
echo "[System] OmniRoute başlatılıyor (/app/data)..."
node run-standalone.mjs