71 lines
2.0 KiB
Python
71 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
"""dylive: turn off neko_enabled on all but one; stop extras. Prevent OOM restart loop."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
KEEP = 2 # hackrobotlite
|
|
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(
|
|
"107.173.30.245",
|
|
22,
|
|
"root",
|
|
"Xiao4669805",
|
|
timeout=40,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
banner_timeout=120,
|
|
)
|
|
_i, o, e = c.exec_command(
|
|
f"""
|
|
set +e
|
|
cd /opt/douyinWEB/backend
|
|
./.venv/bin/python - <<'PY'
|
|
from app import yt_assign_db
|
|
KEEP = {KEEP}
|
|
changed = []
|
|
for g in yt_assign_db.list_groups(include_urls=False, include_secret=False):
|
|
nid = int(g.get('neko_instance_id') or 0)
|
|
en = bool(g.get('neko_enabled'))
|
|
if nid == KEEP:
|
|
if not en:
|
|
yt_assign_db.update_group(g['id'], neko_enabled=True)
|
|
changed.append(('on', g.get('name'), nid))
|
|
continue
|
|
if en:
|
|
yt_assign_db.update_group(g['id'], neko_enabled=False)
|
|
changed.append(('off', g.get('name'), nid))
|
|
print('changed', changed)
|
|
# sync without reconcile_running (don't stop/start blindly beyond flags)
|
|
from app import youtube_neko
|
|
print(youtube_neko.sync_for_groups(yt_assign_db.list_groups(include_urls=False), reconcile_running=False))
|
|
PY
|
|
|
|
# stop every running neko except KEEP
|
|
for n in $(docker ps --format '{{{{.Names}}}}' | grep '^douyinweb-neko-'); do
|
|
case "$n" in
|
|
douyinweb-neko-{KEEP}) echo keep $n ;;
|
|
*) echo stop $n; docker stop "$n" ;;
|
|
esac
|
|
done
|
|
# ensure KEEP up
|
|
docker start douyinweb-neko-{KEEP} 2>/dev/null || true
|
|
sleep 8
|
|
docker ps --filter name=douyinweb-neko --format '{{{{.Names}}}} {{{{.Status}}}}' | sort -V
|
|
free -m | head -2
|
|
uptime
|
|
curl -sS -m 8 -o /dev/null -w 'fe:%{{{{http_code}}}}\\n' http://127.0.0.1:4015/youtube
|
|
curl -sS -m 8 -o /dev/null -w 'api:%{{{{http_code}}}}\\n' http://127.0.0.1:8014/api/health
|
|
""",
|
|
timeout=180,
|
|
)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"))
|
|
c.close()
|
|
print("DONE")
|