douyinWEB/scripts/_fix_dylive_browser_launch_lf.py
2026-09-13 22:10:49 -05:00

94 lines
3.1 KiB
Python

#!/usr/bin/env python3
"""Fix dylive neko-12 browser-launch CRLF/corrupt + start chrome."""
from __future__ import annotations
import sys
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"
# force LF
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())
c.connect(
"107.173.30.245",
22,
"root",
"Xiao4669805",
timeout=60,
allow_agent=False,
look_for_keys=False,
banner_timeout=300,
)
return c
c = connect()
sftp = c.open_sftp()
with sftp.file("/tmp/browser-launch-lf.sh", "wb") as f:
f.write(raw)
sftp.chmod("/tmp/browser-launch-lf.sh", 0o755)
sftp.close()
_i, o, e = c.exec_command(
r"""
set -euo pipefail
# overwrite ALL browser-launch copies with LF version
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-lf.sh > "$f"
chmod 755 "$f"
# strip any leftover CR
sed -i 's/\r$//' "$f" || true
done
file /opt/douyinWEB/backend/neko/browser-launch.sh
head -1 /opt/douyinWEB/backend/neko/browser-launch.sh | od -c | head -2
grep -n jitless /opt/douyinWEB/backend/neko/browser-launch.sh | head -2
# patch mounted inode for neko-12
INO=$(docker exec douyinweb-neko-12 sh -c 'ls -li /etc/neko/browser-launch.sh' | awk '{print $1}')
MATCH=$(ls -li /opt/douyinWEB/backend/neko/browser-launch.sh* | awk -v i="$INO" '$1==i{print $NF; exit}')
echo INO=$INO MATCH=$MATCH
cat /tmp/browser-launch-lf.sh > "$MATCH"
sed -i 's/\r$//' "$MATCH" || true
docker exec douyinweb-neko-12 sh -c 'head -1 /etc/neko/browser-launch.sh | od -c | head -2; grep -n jitless /etc/neko/browser-launch.sh | head; sh -n /etc/neko/browser-launch.sh && echo syntax_ok'
# show last chrome log
docker exec douyinweb-neko-12 sh -c 'tail -50 /var/log/neko/google-chrome.log 2>/dev/null || true'
# clear locks and start
docker exec douyinweb-neko-12 sh -c '
rm -f /home/neko/.config/google-chrome/Singleton* /home/neko/.config/chromium/Singleton* 2>/dev/null || true
supervisorctl clear google-chrome || true
supervisorctl update || true
supervisorctl start google-chrome || supervisorctl restart google-chrome
sleep 8
supervisorctl status google-chrome
'
# if still bad, run launch manually for error
docker exec douyinweb-neko-12 sh -c '
if ! supervisorctl status google-chrome | grep -q RUNNING; then
echo MANUAL_TRY
su -s /bin/sh neko -c "DISPLAY=:99.0 /etc/neko/browser-launch.sh google-chrome" > /tmp/chrome-manual.log 2>&1 &
sleep 3
tail -40 /tmp/chrome-manual.log || true
tail -40 /var/log/neko/google-chrome.log || true
fi
curl -sS -m 3 http://127.0.0.1:9222/json/version || echo no_devtools
'
docker ps --filter name=douyinweb-neko-12 --format '{{.Names}} {{.Status}}'
""",
timeout=120,
)
print((o.read() + e.read()).decode("utf-8", "replace"))
c.close()
print("DONE")