81 lines
2.7 KiB
Python
81 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Diagnose + recover dy neko-10 chrome after launch sync."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
raw = (
|
|
Path(__file__).resolve().parents[1] / "backend" / "neko" / "browser-launch.sh"
|
|
).read_bytes().replace(b"\r\n", b"\n").replace(b"\r", b"\n")
|
|
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(
|
|
"108.174.50.68",
|
|
22,
|
|
"root",
|
|
"Xiao4669805",
|
|
timeout=60,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
banner_timeout=300,
|
|
)
|
|
sftp = c.open_sftp()
|
|
with sftp.file("/tmp/browser-launch-lf.sh", "wb") as f:
|
|
f.write(raw)
|
|
sftp.close()
|
|
|
|
_i, o, e = c.exec_command(
|
|
r"""
|
|
set +e
|
|
echo '=== file check ==='
|
|
file /opt/douyinWEB/backend/neko/browser-launch.sh
|
|
head -1 /opt/douyinWEB/backend/neko/browser-launch.sh | od -c | head -1
|
|
docker exec douyinweb-neko-10 sh -c 'file /etc/neko/browser-launch.sh; head -1 /etc/neko/browser-launch.sh | od -c | head -1; sh -n /etc/neko/browser-launch.sh && echo syntax_ok; grep -n js-flags /etc/neko/browser-launch.sh | head -1'
|
|
|
|
echo '=== chrome log ==='
|
|
docker exec douyinweb-neko-10 sh -c 'tail -40 /var/log/neko/google-chrome.log 2>/dev/null; ls -la /var/log/neko/ 2>/dev/null | head'
|
|
docker exec douyinweb-neko-10 sh -c 'tail -40 /var/log/supervisor/google-chrome*.log 2>/dev/null; ls /var/log/supervisor/ 2>/dev/null'
|
|
|
|
echo '=== rewrite inode + start ==='
|
|
INO=$(docker exec douyinweb-neko-10 sh -c 'ls -li /etc/neko/browser-launch.sh' | awk '{print $1}')
|
|
MATCH=$(find /opt /root -xdev -inum "$INO" 2>/dev/null | head -1)
|
|
echo INO=$INO MATCH=$MATCH
|
|
if [ -n "$MATCH" ]; then
|
|
cat /tmp/browser-launch-lf.sh > "$MATCH"
|
|
chmod 755 "$MATCH"
|
|
fi
|
|
cat /tmp/browser-launch-lf.sh > /opt/douyinWEB/backend/neko/browser-launch.sh
|
|
chmod 755 /opt/douyinWEB/backend/neko/browser-launch.sh
|
|
|
|
docker exec douyinweb-neko-10 sh -c '
|
|
sh -n /etc/neko/browser-launch.sh && echo syntax_ok2
|
|
rm -f /home/neko/.config/google-chrome/Singleton* /tmp/.com.google.Chrome* 2>/dev/null
|
|
# try run once manually to see error
|
|
timeout 8 /etc/neko/browser-launch.sh 2>&1 | tail -30 || true
|
|
supervisorctl start google-chrome
|
|
sleep 10
|
|
supervisorctl status google-chrome
|
|
curl -sS -m 3 http://127.0.0.1:9222/json/version || echo no_devtools
|
|
python3 - <<PY
|
|
import json,urllib.request
|
|
try:
|
|
tabs=json.load(urllib.request.urlopen("http://127.0.0.1:9222/json",timeout=5))
|
|
print("tabs",len(tabs))
|
|
for t in tabs[:4]:
|
|
print(t.get("type"), (t.get("url") or "")[:90])
|
|
except Exception as e:
|
|
print("tabs_err",e)
|
|
PY
|
|
'
|
|
""",
|
|
timeout=180,
|
|
)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"))
|
|
c.close()
|
|
print("DONE")
|