Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP. Co-authored-by: Cursor <cursoragent@cursor.com>
74 lines
2.1 KiB
Python
74 lines
2.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Wipe imported monitor.db on dy.nomadro.live — fresh install must have zero rooms."""
|
|
import sys
|
|
import time
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
HOST = "108.174.50.68"
|
|
WIPE_SH = r"""#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
source /etc/douyinweb.env
|
|
export DY_SESSION_SECRET="${SESSION_SECRET:-}"
|
|
APP_DIR=/opt/douyinWEB
|
|
DB="$APP_DIR/backend/data/monitor.db"
|
|
|
|
echo "=== before ==="
|
|
if [ -f "$DB" ]; then
|
|
sqlite3 "$DB" "SELECT COUNT(*) AS rooms FROM rooms;" || true
|
|
else
|
|
echo "no db"
|
|
fi
|
|
|
|
systemctl stop douyinweb-api
|
|
rm -f "$DB" "$DB-shm" "$DB-wal"
|
|
|
|
systemctl start douyinweb-api
|
|
sleep 5
|
|
|
|
cd "$APP_DIR/backend"
|
|
.venv/bin/python -c "from app.session_auth import ensure_default_admin_credentials; ensure_default_admin_credentials()"
|
|
|
|
echo "=== after ==="
|
|
sqlite3 "$DB" "SELECT COUNT(*) AS rooms FROM rooms;"
|
|
curl -sS "http://127.0.0.1:${API_PORT:-8014}/api/health" | head -c 200; echo
|
|
echo DONE
|
|
"""
|
|
|
|
|
|
def main() -> int:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(HOST, 22, "root", "Xiao4669805", timeout=45, allow_agent=False, look_for_keys=False)
|
|
|
|
remote = "/tmp/wipe_dy_rooms.sh"
|
|
sftp = c.open_sftp()
|
|
with sftp.file(remote, "w") as f:
|
|
f.write(WIPE_SH)
|
|
sftp.chmod(remote, 0o755)
|
|
sftp.close()
|
|
|
|
chan = c.get_transport().open_session()
|
|
chan.settimeout(120)
|
|
chan.get_pty(width=200, height=50)
|
|
chan.exec_command(f"bash {remote}")
|
|
while True:
|
|
if chan.recv_ready():
|
|
print(chan.recv(65535).decode("utf-8", "replace"), end="", flush=True)
|
|
if chan.recv_stderr_ready():
|
|
print(chan.recv_stderr(65535).decode("utf-8", "replace"), end="", flush=True)
|
|
if chan.exit_status_ready() and not chan.recv_ready() and not chan.recv_stderr_ready():
|
|
break
|
|
time.sleep(0.3)
|
|
while chan.recv_ready():
|
|
print(chan.recv(65535).decode("utf-8", "replace"), end="", flush=True)
|
|
code = chan.recv_exit_status()
|
|
c.close()
|
|
print(f"\nexit {code}")
|
|
return code
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|