138 lines
4.2 KiB
Python
138 lines
4.2 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""Restart Neko containers to remount browser-launch bind (profile volumes untouched)."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
|
|
def run_phys() -> None:
|
|
script = r"""#!/bin/bash
|
|
set -e
|
|
NAMES=$(docker ps --format '{{.Names}}' | grep -E 'douyinweb-(neko-|ops-neko-)' | sort)
|
|
echo "restarting:" $NAMES
|
|
for N in $NAMES; do
|
|
docker restart "$N"
|
|
done
|
|
echo wait...
|
|
sleep 35
|
|
for N in $NAMES; do
|
|
lines=$(docker exec "$N" wc -l /etc/neko/browser-launch.sh 2>/dev/null | awk '{print $1}')
|
|
trap=$(docker exec "$N" grep -c on_supervisor_stop /etc/neko/browser-launch.sh 2>/dev/null || echo 0)
|
|
out=$(docker exec -i "$N" python3 - <<'PY'
|
|
import os, json, urllib.request
|
|
mains=0; load=False; sw=-1
|
|
for pid in os.listdir("/proc"):
|
|
if not pid.isdigit(): continue
|
|
try: raw=open(f"/proc/{pid}/cmdline","rb").read()
|
|
except: continue
|
|
if not raw: continue
|
|
if b"google-chrome" in raw and b"--type=" not in raw and b"crashpad" not in raw and b"browser-launch" not in raw:
|
|
mains += 1
|
|
if b"load-extension" in raw and b"dhdgff" in raw: load=True
|
|
try:
|
|
tabs=json.loads(urllib.request.urlopen("http://127.0.0.1:9222/json/list",timeout=3).read())
|
|
sw=sum(1 for t in tabs if t.get("type")=="service_worker" and "dhdgff" in (t.get("url") or ""))
|
|
except Exception:
|
|
sw=-1
|
|
print(f"mains={mains} load_ext={load} tm_sw={sw}")
|
|
PY
|
|
)
|
|
echo "$N lines=$lines trap=$trap $out"
|
|
done
|
|
curl -sS -m 8 -o /dev/null -w 'cn_neko3=%{http_code}\n' https://dy.nomadro.cn/neko/3/ || true
|
|
"""
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(
|
|
"107.173.30.245",
|
|
4014,
|
|
"eric",
|
|
"4669805",
|
|
timeout=45,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
banner_timeout=120,
|
|
)
|
|
sftp = c.open_sftp()
|
|
with sftp.file("/tmp/_restart_phys_nekos_remount.sh", "w") as f:
|
|
f.write(script)
|
|
sftp.close()
|
|
print("===== PHYSICAL =====")
|
|
_i, o, e = c.exec_command(
|
|
"echo '4669805' | sudo -S -p '' bash /tmp/_restart_phys_nekos_remount.sh",
|
|
timeout=420,
|
|
)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"))
|
|
c.close()
|
|
|
|
|
|
def run_vps() -> None:
|
|
script = r"""#!/bin/bash
|
|
set -e
|
|
NAMES=$(docker ps --format '{{.Names}}' | grep -E 'douyinweb-neko-[0-9]+$' | sort)
|
|
echo "restarting:" $NAMES
|
|
for N in $NAMES; do
|
|
docker restart "$N"
|
|
done
|
|
sleep 30
|
|
for N in $NAMES; do
|
|
lines=$(docker exec "$N" wc -l /etc/neko/browser-launch.sh | awk '{print $1}')
|
|
trap=$(docker exec "$N" grep -c on_supervisor_stop /etc/neko/browser-launch.sh || echo 0)
|
|
out=$(docker exec -i "$N" python3 - <<'PY'
|
|
import os, json, urllib.request
|
|
mains=0; load=False; sw=-1
|
|
for pid in os.listdir("/proc"):
|
|
if not pid.isdigit(): continue
|
|
try: raw=open(f"/proc/{pid}/cmdline","rb").read()
|
|
except: continue
|
|
if not raw: continue
|
|
if b"google-chrome" in raw and b"--type=" not in raw and b"crashpad" not in raw and b"browser-launch" not in raw:
|
|
mains += 1
|
|
if b"load-extension" in raw and b"dhdgff" in raw: load=True
|
|
try:
|
|
tabs=json.loads(urllib.request.urlopen("http://127.0.0.1:9222/json/list",timeout=3).read())
|
|
sw=sum(1 for t in tabs if t.get("type")=="service_worker" and "dhdgff" in (t.get("url") or ""))
|
|
except Exception:
|
|
sw=-1
|
|
print(f"mains={mains} load_ext={load} tm_sw={sw}")
|
|
PY
|
|
)
|
|
echo "$N lines=$lines trap=$trap $out"
|
|
done
|
|
curl -sS -m 8 -o /dev/null -w 'dylive_neko7=%{http_code}\n' https://dylive.nomadro.com/neko/7/ || true
|
|
"""
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(
|
|
"107.173.30.245",
|
|
22,
|
|
"root",
|
|
"Xiao4669805",
|
|
timeout=30,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
banner_timeout=60,
|
|
)
|
|
sftp = c.open_sftp()
|
|
with sftp.file("/tmp/_restart_vps_nekos_remount.sh", "w") as f:
|
|
f.write(script)
|
|
sftp.close()
|
|
print("===== VPS =====")
|
|
_i, o, e = c.exec_command("bash /tmp/_restart_vps_nekos_remount.sh", timeout=300)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"))
|
|
c.close()
|
|
|
|
|
|
def main() -> None:
|
|
run_phys()
|
|
run_vps()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|