120 lines
3.9 KiB
Python
120 lines
3.9 KiB
Python
#!/usr/bin/env python3
|
|
"""Recover dylive neko-6 Chrome FATAL — no container recreate."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
LOCAL = Path(__file__).resolve().parents[1] / "backend" / "neko" / "browser-launch.sh"
|
|
raw = LOCAL.read_bytes().replace(b"\r\n", b"\n").replace(b"\r", b"\n")
|
|
assert b"--jitless" in raw
|
|
|
|
|
|
def connect():
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
for i in range(10):
|
|
try:
|
|
c.connect(
|
|
"107.173.30.245",
|
|
22,
|
|
"root",
|
|
"Xiao4669805",
|
|
timeout=60,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
banner_timeout=300,
|
|
)
|
|
return c
|
|
except Exception as e:
|
|
print("retry", i, e, flush=True)
|
|
time.sleep(2 + i)
|
|
raise SystemExit("ssh fail")
|
|
|
|
|
|
c = connect()
|
|
sftp = c.open_sftp()
|
|
with sftp.file("/tmp/browser-launch-neko6.sh", "wb") as f:
|
|
f.write(raw)
|
|
sftp.chmod("/tmp/browser-launch-neko6.sh", 0o755)
|
|
sftp.close()
|
|
|
|
_i, o, e = c.exec_command(
|
|
r"""
|
|
set -euo pipefail
|
|
NAME=douyinweb-neko-6
|
|
|
|
# sync host + any bak inodes
|
|
for f in /opt/douyinWEB/backend/neko/browser-launch.sh /opt/douyinWEB/backend/neko/browser-launch.sh.bak-sigill*; do
|
|
[ -e "$f" ] || continue
|
|
cat /tmp/browser-launch-neko6.sh > "$f"
|
|
chmod 755 "$f"
|
|
sed -i 's/\r$//' "$f" || true
|
|
done
|
|
|
|
# patch the exact inode mounted into this container
|
|
INO=$(docker exec "$NAME" sh -c 'ls -li /etc/neko/browser-launch.sh' | awk '{print $1}')
|
|
MATCH=$(ls -li /opt/douyinWEB/backend/neko/browser-launch.sh* 2>/dev/null | awk -v i="$INO" '$1==i{print $NF; exit}')
|
|
echo INO=$INO MATCH=$MATCH
|
|
if [ -n "${MATCH:-}" ] && [ -e "$MATCH" ]; then
|
|
cat /tmp/browser-launch-neko6.sh > "$MATCH"
|
|
sed -i 's/\r$//' "$MATCH" || true
|
|
else
|
|
# fallback: docker cp into running container (persists until recreate — ok)
|
|
docker cp /tmp/browser-launch-neko6.sh "$NAME":/etc/neko/browser-launch.sh
|
|
docker exec "$NAME" chmod 755 /etc/neko/browser-launch.sh
|
|
fi
|
|
|
|
docker exec "$NAME" sh -c 'head -1 /etc/neko/browser-launch.sh | od -c | head -2; grep -n jitless /etc/neko/browser-launch.sh | head -2; sh -n /etc/neko/browser-launch.sh && echo syntax_ok'
|
|
docker exec "$NAME" sh -c 'tail -60 /var/log/neko/google-chrome.log 2>/dev/null || echo no_chrome_log'
|
|
|
|
# kill leftover chrome from manual probe; clear locks; fix cache dir perms
|
|
docker exec "$NAME" sh -c '
|
|
pkill -u neko -f "[g]oogle-chrome" 2>/dev/null || true
|
|
pkill -u neko -f "[c]hrome" 2>/dev/null || true
|
|
sleep 1
|
|
rm -f /home/neko/.config/google-chrome/Singleton* /home/neko/.config/chromium/Singleton* 2>/dev/null || true
|
|
mkdir -p "/home/neko/.config/google-chrome/Default/Shared Dictionary/cache"
|
|
chown -R neko:neko /home/neko/.config/google-chrome 2>/dev/null || true
|
|
supervisorctl stop google-chrome || true
|
|
sleep 1
|
|
supervisorctl clear google-chrome || true
|
|
supervisorctl start google-chrome
|
|
sleep 10
|
|
supervisorctl status
|
|
'
|
|
|
|
docker exec "$NAME" sh -c '
|
|
curl -sS -m 5 http://127.0.0.1:9222/json/version | head -c 500; echo
|
|
# count chrome procs via /proc
|
|
n=0
|
|
for p in /proc/[0-9]*; do
|
|
cmd=$(tr "\0" " " < "$p/cmdline" 2>/dev/null || true)
|
|
case "$cmd" in *chrome*) n=$((n+1));; esac
|
|
done
|
|
echo chrome_procs=$n
|
|
'
|
|
|
|
# ensure group can open neko if needed (do NOT recreate)
|
|
cd /opt/douyinWEB/backend
|
|
./.venv/bin/python - <<'PY'
|
|
from app import yt_assign_db
|
|
for g in yt_assign_db.list_groups(include_urls=False, include_secret=False):
|
|
if int(g.get("neko_instance_id") or 0) == 6:
|
|
print("group", g.get("name"), "neko_enabled", g.get("neko_enabled"))
|
|
PY
|
|
|
|
docker ps --filter name=douyinweb-neko-6 --format '{{.Names}} {{.Status}}'
|
|
free -m | head -2
|
|
echo NEKO6_CHROME_DONE
|
|
""",
|
|
timeout=180,
|
|
)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"))
|
|
c.close()
|