Sync runtime data (DB, covers, PB) and add Ubuntu deploy script.
Keep monitoring state deployable so remote starts with real rooms and cookie. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
76afafa6c9
commit
86bdcb9a21
11
.gitignore
vendored
11
.gitignore
vendored
@ -13,15 +13,10 @@ node_modules/
|
|||||||
out/
|
out/
|
||||||
*.tsbuildinfo
|
*.tsbuildinfo
|
||||||
|
|
||||||
# Runtime / secrets / local data
|
# Keep runtime data (DB / covers / cookie settings in SQLite) in repo for deploy sync
|
||||||
backend/data/
|
# backend/data/ is tracked intentionally
|
||||||
*.db
|
|
||||||
*.db-*
|
|
||||||
*.sqlite
|
|
||||||
*.sqlite3
|
|
||||||
|
|
||||||
# PocketBase
|
# PocketBase binary (platform-specific); pb_data synced for collections if present
|
||||||
pb/pb_data/
|
|
||||||
pb/pocketbase.exe
|
pb/pocketbase.exe
|
||||||
pb/CHANGELOG.md
|
pb/CHANGELOG.md
|
||||||
pb/LICENSE.md
|
pb/LICENSE.md
|
||||||
|
|||||||
@ -109,6 +109,7 @@ python scripts\sync_cookie_and_probe.py
|
|||||||
|
|
||||||
## 说明
|
## 说明
|
||||||
|
|
||||||
- SQLite 库、封面、PocketBase 数据、`.env`、Cookie 等不入库(见 `.gitignore`)。
|
- 为方便部署同步,仓库包含 `backend/data/`(SQLite、封面、Cookie 设置)与 `pb/pb_data/`。
|
||||||
- `pocketbase.exe` 需自行放入 `pb/`(体积大,未纳入仓库)。
|
- Windows 的 `pocketbase.exe` 不入库;Ubuntu 部署时下载 Linux 版 PocketBase。
|
||||||
- 本项目仅做状态监控与场次统计,不含推流录制;推流逻辑仍在 sh2。
|
- 本项目仅做状态监控与场次统计,不含推流录制;推流逻辑仍在 sh2。
|
||||||
|
|
||||||
|
|||||||
BIN
backend/data/covers/092e99d2-d56c-4066-a0f7-50ce30ae89ca.jpg
Normal file
BIN
backend/data/covers/092e99d2-d56c-4066-a0f7-50ce30ae89ca.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 156 KiB |
BIN
backend/data/covers/2b1516ec-2f91-4790-a461-0642e3280dd6.jpg
Normal file
BIN
backend/data/covers/2b1516ec-2f91-4790-a461-0642e3280dd6.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 178 KiB |
BIN
backend/data/covers/5634855a-5abb-4e2f-96f4-6f9b27a207b3.jpg
Normal file
BIN
backend/data/covers/5634855a-5abb-4e2f-96f4-6f9b27a207b3.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 139 KiB |
BIN
backend/data/covers/8fb1ef1d-c50c-44aa-b44a-b73fb40ac400.jpg
Normal file
BIN
backend/data/covers/8fb1ef1d-c50c-44aa-b44a-b73fb40ac400.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 241 KiB |
BIN
backend/data/covers/94536798-14c4-4532-afc3-e4228f52bee4.jpg
Normal file
BIN
backend/data/covers/94536798-14c4-4532-afc3-e4228f52bee4.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 106 KiB |
BIN
backend/data/covers/fb37465e-bd00-465f-9720-e6e37c9ae6c7.jpg
Normal file
BIN
backend/data/covers/fb37465e-bd00-465f-9720-e6e37c9ae6c7.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 106 KiB |
1859
backend/data/import_rooms.json
Normal file
1859
backend/data/import_rooms.json
Normal file
File diff suppressed because it is too large
Load Diff
BIN
backend/data/monitor.db
Normal file
BIN
backend/data/monitor.db
Normal file
Binary file not shown.
1
backend/data/stats_out.txt
Normal file
1
backend/data/stats_out.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"overview":{"sessions":2,"unique_anchors":2,"active_sessions":0,"total_hours":4.0,"avg_duration_seconds":7200,"median_duration_seconds":7200,"days_span":2,"date_from":"2026-08-06","date_to":"2026-08-08"},"top_anchors":[{"anchor_name":"示例主播2","source_room_id":"234567890123","sessions":1,"hours_total":2.5,"avg_duration_seconds":9000,"peak_hour":23,"peak_weekday_label":"周四","dates_active":1,"sessions_per_active_day":1.0,"avg_gap_hours":null},{"anchor_name":"示例主播1","source_room_id":"123456789012","sessions":1,"hours_total":1.5,"avg_duration_seconds":5400,"peak_hour":0,"peak_weekday_label":"周六","dates_active":1,"sessions_per_active_day":1.0,"avg_gap_hours":null}],"by_hour":{"starts":[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],"minutes":[70.2,120.0,39.5,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,10.2],"labels":["00:00","01:00","02:00","03:00","04:00","05:00","06:00","07:00","08:00","09:00","10:00","11:00","12:00","13:00","14:00","15:00","16:00","17:00","18:00","19:00","20:00","21:00","22:00","23:00"]},"by_weekday":{"starts":[0,0,0,1,0,1,0],"minutes":[0.0,0.0,0.0,10.2,139.8,90.0,0.0],"labels":["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],"labels_zh":["周一","周二","周三","周四","周五","周六","周日"]},"heatmap":{"starts":[[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]],"minutes":[[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,10.2],[60.0,60.0,19.8,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],[10.2,60.0,19.8,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],[0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0]],"weekday_labels":["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],"weekday_labels_zh":["周一","周二","周三","周四","周五","周六","周日"],"hour_labels":["0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23"]},"by_date":[{"date":"2026-08-06","sessions":1,"hours":2.5,"unique_anchors":1},{"date":"2026-08-08","sessions":1,"hours":1.5,"unique_anchors":1}],"duration_buckets":{"<15m":0,"15-60m":0,"1-3h":2,"3-6h":0,"6-12h":0,">12h":0},"insights":[{"zh":"最常开播时段:00:00–00:59;最常开播星期:周四。","en":"Busiest hour: 00:00; busiest weekday: Thu."},{"zh":"开播最多主播:示例主播2(1 场 / 2.5 小时)。","en":"Top anchor: 示例主播2 (1 sessions / 2.5h)."}]}
|
||||||
BIN
pb/pb_data/auxiliary.db
Normal file
BIN
pb/pb_data/auxiliary.db
Normal file
Binary file not shown.
BIN
pb/pb_data/auxiliary.db-shm
Normal file
BIN
pb/pb_data/auxiliary.db-shm
Normal file
Binary file not shown.
BIN
pb/pb_data/auxiliary.db-wal
Normal file
BIN
pb/pb_data/auxiliary.db-wal
Normal file
Binary file not shown.
BIN
pb/pb_data/data.db
Normal file
BIN
pb/pb_data/data.db
Normal file
Binary file not shown.
BIN
pb/pb_data/data.db-shm
Normal file
BIN
pb/pb_data/data.db-shm
Normal file
Binary file not shown.
BIN
pb/pb_data/data.db-wal
Normal file
BIN
pb/pb_data/data.db-wal
Normal file
Binary file not shown.
24372
pb/pb_data/types.d.ts
vendored
Normal file
24372
pb/pb_data/types.d.ts
vendored
Normal file
File diff suppressed because it is too large
Load Diff
185
scripts/deploy_ubuntu.py
Normal file
185
scripts/deploy_ubuntu.py
Normal file
@ -0,0 +1,185 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""Deploy douyinWEB to Ubuntu via SSH (paramiko)."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
|
import paramiko
|
||||||
|
|
||||||
|
HOST = "107.173.30.245"
|
||||||
|
PORT = 4014
|
||||||
|
USER = "eric"
|
||||||
|
PASSWORD = "4669805"
|
||||||
|
|
||||||
|
GIT_URL = "https://eric:Xiao4669805@gitea.dsx2020.com/eric/douyinWEB.git"
|
||||||
|
APP_DIR = "/home/eric/douyinWEB"
|
||||||
|
|
||||||
|
|
||||||
|
def run(client: paramiko.SSHClient, cmd: str, timeout: int = 600) -> tuple[int, str, str]:
|
||||||
|
print(f"\n$ {cmd}", flush=True)
|
||||||
|
stdin, stdout, stderr = client.exec_command(cmd, timeout=timeout, get_pty=True)
|
||||||
|
out = stdout.read().decode("utf-8", errors="replace")
|
||||||
|
err = stderr.read().decode("utf-8", errors="replace")
|
||||||
|
code = stdout.channel.recv_exit_status()
|
||||||
|
if out.strip():
|
||||||
|
print(out[-4000:], flush=True)
|
||||||
|
if err.strip():
|
||||||
|
print("[stderr]", err[-2000:], flush=True)
|
||||||
|
print(f"[exit {code}]", flush=True)
|
||||||
|
return code, out, err
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> int:
|
||||||
|
client = paramiko.SSHClient()
|
||||||
|
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||||
|
print(f"connecting {USER}@{HOST}:{PORT} ...", flush=True)
|
||||||
|
client.connect(HOST, port=PORT, username=USER, password=PASSWORD, timeout=30, allow_agent=False, look_for_keys=False)
|
||||||
|
print("connected", flush=True)
|
||||||
|
|
||||||
|
# basic env
|
||||||
|
run(client, "uname -a; whoami; pwd; df -h / | tail -1")
|
||||||
|
run(
|
||||||
|
client,
|
||||||
|
"command -v git; command -v python3; command -v node; command -v npm; command -v ffmpeg; command -v curl",
|
||||||
|
)
|
||||||
|
|
||||||
|
# clone or pull (force sync to remote main with data)
|
||||||
|
run(
|
||||||
|
client,
|
||||||
|
f"""
|
||||||
|
set -e
|
||||||
|
if [ -d {APP_DIR}/.git ]; then
|
||||||
|
cd {APP_DIR}
|
||||||
|
git remote set-url origin '{GIT_URL}'
|
||||||
|
git fetch origin
|
||||||
|
git reset --hard origin/main
|
||||||
|
else
|
||||||
|
rm -rf {APP_DIR}
|
||||||
|
git clone '{GIT_URL}' {APP_DIR}
|
||||||
|
fi
|
||||||
|
cd {APP_DIR}
|
||||||
|
git log -1 --oneline
|
||||||
|
ls -la
|
||||||
|
ls -la backend/data || true
|
||||||
|
""".strip(),
|
||||||
|
)
|
||||||
|
|
||||||
|
# install system deps if missing
|
||||||
|
run(
|
||||||
|
client,
|
||||||
|
"""
|
||||||
|
set -e
|
||||||
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
|
sudo -n true 2>/dev/null && SUDO=sudo || SUDO=
|
||||||
|
$SUDO apt-get update -y
|
||||||
|
$SUDO apt-get install -y python3-pip python3-venv nodejs npm ffmpeg curl unzip ca-certificates
|
||||||
|
python3 --version
|
||||||
|
node --version || true
|
||||||
|
npm --version || true
|
||||||
|
ffmpeg -version | head -1 || true
|
||||||
|
""".strip(),
|
||||||
|
timeout=900,
|
||||||
|
)
|
||||||
|
|
||||||
|
# pocketbase linux binary
|
||||||
|
run(
|
||||||
|
client,
|
||||||
|
f"""
|
||||||
|
set -e
|
||||||
|
cd {APP_DIR}/pb
|
||||||
|
if [ ! -x ./pocketbase ]; then
|
||||||
|
curl -L -o pb.zip https://github.com/pocketbase/pocketbase/releases/download/v0.25.8/pocketbase_0.25.8_linux_amd64.zip
|
||||||
|
unzip -o pb.zip pocketbase
|
||||||
|
chmod +x pocketbase
|
||||||
|
rm -f pb.zip
|
||||||
|
fi
|
||||||
|
./pocketbase --version || true
|
||||||
|
ls -la
|
||||||
|
""".strip(),
|
||||||
|
timeout=300,
|
||||||
|
)
|
||||||
|
|
||||||
|
# python venv + deps
|
||||||
|
run(
|
||||||
|
client,
|
||||||
|
f"""
|
||||||
|
set -e
|
||||||
|
cd {APP_DIR}/backend
|
||||||
|
python3 -m venv .venv
|
||||||
|
. .venv/bin/activate
|
||||||
|
pip install -U pip
|
||||||
|
pip install -r requirements.txt
|
||||||
|
""".strip(),
|
||||||
|
timeout=600,
|
||||||
|
)
|
||||||
|
|
||||||
|
# frontend deps + build (production)
|
||||||
|
run(
|
||||||
|
client,
|
||||||
|
f"""
|
||||||
|
set -e
|
||||||
|
cd {APP_DIR}/frontend
|
||||||
|
npm install --no-fund --no-audit
|
||||||
|
npm run build
|
||||||
|
""".strip(),
|
||||||
|
timeout=900,
|
||||||
|
)
|
||||||
|
|
||||||
|
# stop old processes
|
||||||
|
run(
|
||||||
|
client,
|
||||||
|
f"""
|
||||||
|
set +e
|
||||||
|
pkill -f 'pocketbase serve' || true
|
||||||
|
pkill -f 'uvicorn app.main:app' || true
|
||||||
|
pkill -f 'next start' || true
|
||||||
|
pkill -f 'next-server' || true
|
||||||
|
sleep 2
|
||||||
|
echo stopped
|
||||||
|
""".strip(),
|
||||||
|
)
|
||||||
|
|
||||||
|
# start services with nohup
|
||||||
|
run(
|
||||||
|
client,
|
||||||
|
f"""
|
||||||
|
set -e
|
||||||
|
cd {APP_DIR}
|
||||||
|
mkdir -p logs
|
||||||
|
|
||||||
|
# PocketBase
|
||||||
|
nohup ./pb/pocketbase serve --http=127.0.0.1:8090 > logs/pb.log 2>&1 &
|
||||||
|
echo $! > logs/pb.pid
|
||||||
|
|
||||||
|
# FastAPI
|
||||||
|
cd {APP_DIR}/backend
|
||||||
|
nohup .venv/bin/python -m uvicorn app.main:app --host 0.0.0.0 --port 8000 > ../logs/api.log 2>&1 &
|
||||||
|
echo $! > ../logs/api.pid
|
||||||
|
|
||||||
|
# Next.js production
|
||||||
|
cd {APP_DIR}/frontend
|
||||||
|
nohup npm run start -- --port 3000 --hostname 0.0.0.0 > ../logs/web.log 2>&1 &
|
||||||
|
echo $! > ../logs/web.pid
|
||||||
|
|
||||||
|
sleep 5
|
||||||
|
ss -lntp | grep -E ':3000|:8000|:8090' || netstat -lntp 2>/dev/null | grep -E ':3000|:8000|:8090' || true
|
||||||
|
curl -s --max-time 8 http://127.0.0.1:8000/api/health || true
|
||||||
|
echo
|
||||||
|
curl -s -o /dev/null -w 'web:%{{http_code}}\\n' --max-time 15 http://127.0.0.1:3000/ || true
|
||||||
|
echo DONE
|
||||||
|
""".strip(),
|
||||||
|
timeout=120,
|
||||||
|
)
|
||||||
|
|
||||||
|
client.close()
|
||||||
|
print("\nDeploy finished. Open http://107.173.30.245:3000 (if firewall allows)", flush=True)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
try:
|
||||||
|
raise SystemExit(main())
|
||||||
|
except Exception as exc:
|
||||||
|
print("DEPLOY FAILED:", type(exc).__name__, exc, flush=True)
|
||||||
|
raise
|
||||||
Loading…
Reference in New Issue
Block a user