douyinWEB/scripts/_check_nomdfs_physical.py
eric d409e416da Ship physical dual-edge stack, Studio CDP live metrics, and ops tooling.
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>
2026-09-04 22:42:40 -05:00

71 lines
2.2 KiB
Python

# -*- coding: utf-8 -*-
"""Check nomdfs yt_long orphan linkage on physical."""
from __future__ import annotations
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
PASS = "4669805"
REMOTE = r'''
import sqlite3, json
con=sqlite3.connect("/opt/douyinWEB/backend/data/monitor.db")
con.row_factory=sqlite3.Row
yt="UCk6CoQG0q9grwIr5UgxiXEQ"
oid="cf0c1355-7586-418c-927a-df4762de5774"
print("shorts", [dict(r) for r in con.execute(
"SELECT id,name,enabled,youtube_channel_id FROM shorts_channels WHERE youtube_channel_id=?", (yt,))])
print("yt_long", [dict(r) for r in con.execute(
"SELECT id,name,enabled,source_shorts_channel_pk,youtube_channel_id FROM yt_long_channels WHERE youtube_channel_id=? OR id=?",
(yt, oid))])
print("jobs", [dict(r) for r in con.execute(
"SELECT id,status,channel_pk FROM yt_long_jobs WHERE channel_pk=?", (oid,))])
# env check via systemctl show
import subprocess
out=subprocess.check_output(
["systemctl","show","douyinweb-api","-p","Environment","--no-pager"],
text=True, errors="replace")
for key in ("DY_NEKO_GATEWAY_ENABLED","DY_NEKO_MAX_INSTANCES","DY_NEKO_NAT1TO1"):
print(key, key+"=" in out, [x for x in out.replace("\n"," ").split() if x.startswith(key+"=")])
'''
def main():
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
for i in range(8):
try:
c.connect(
"107.173.30.245",
4014,
"eric",
PASS,
timeout=60,
banner_timeout=120,
allow_agent=False,
look_for_keys=False,
)
break
except Exception as ex:
print("ssh", i, type(ex).__name__, flush=True)
time.sleep(2 + i)
else:
raise SystemExit("ssh failed")
sftp = c.open_sftp()
with sftp.file("/tmp/_check_nomdfs.py", "w") as f:
f.write(REMOTE)
sftp.close()
_, o, e = c.exec_command(
f"echo '{PASS}' | sudo -S -p '' python3 /tmp/_check_nomdfs.py",
timeout=60,
)
print((o.read() + e.read()).decode("utf-8", "replace"), flush=True)
c.close()
if __name__ == "__main__":
main()