This commit is contained in:
zaiun xu
2026-04-09 15:21:21 +08:00
parent 5e1b2117c1
commit e1b514836e
8 changed files with 129 additions and 96 deletions

View File

@@ -1,69 +1,9 @@
#!/usr/bin/env bash
# 一键启动 Fish API删除整个 SQLite 库文件(含 -wal/-shm并删除旧版 watch JSON 状态文件,再启动服务
# 与 start.sh 相同(历史名称保留):清空状态后启动 Fish API
#
# bash fish_api/start_fresh.sh
# PORT=8001 HOST=0.0.0.0 bash fish_api/start_fresh.sh
#
# 首次使用请先cd fish_api && uv sync
#
set -euo pipefail
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$DIR"
export PUBLIC_BASE_URL="${PUBLIC_BASE_URL:-http://127.0.0.1:8000}"
unset PYTHON_FISH_MEASURE PYTHON_FISH_ACTION 2>/dev/null || true
if command -v uv >/dev/null 2>&1; then
PY=(uv run python)
else
PY=(python3)
fi
"${PY[@]}" - <<'PY'
from pathlib import Path
from app.db import remove_sqlite_database_files
from app.settings import get_settings
s = get_settings()
def _rm(path: Path | None) -> None:
if path is None:
return
try:
if path.is_file():
path.unlink()
print(f"[start-fresh] removed legacy JSON {path}", flush=True)
except OSError as e:
print(f"[start-fresh] skip {path}: {e}", flush=True)
remove_sqlite_database_files(s)
print(f"[start-fresh] removed SQLite database at {s.sqlite_path} (and -wal/-shm if present).", flush=True)
# 旧版 JSON 若仍存在,启动时会被 load_watch_processed 合并进 SQLite必须一并删除
if s.measure_watch_use_state_file:
if s.measure_watch_state_file is not None:
_rm(s.measure_watch_state_file)
elif s.measure_watch_dir is not None:
_rm(s.measure_watch_dir / ".fishmeasure_watch_processed.json")
if s.action_watch_use_state_file:
if s.action_watch_state_file is not None:
_rm(s.action_watch_state_file)
elif s.action_watch_dir is not None:
_rm(s.action_watch_dir / ".fishaction_watch_processed.json")
print("[start-fresh] done.", flush=True)
PY
PORT="${PORT:-8000}"
HOST="${HOST:-0.0.0.0}"
if command -v uv >/dev/null 2>&1; then
exec uv run uvicorn app.main:app --host "$HOST" --port "$PORT"
else
exec uvicorn app.main:app --host "$HOST" --port "$PORT"
fi
exec bash "$DIR/start.sh"