197 lines
7.0 KiB
Python
197 lines
7.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Fix dy neko-10 SIGILL (jitless) + timeslot context. Never recreate container."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
HOST = "108.174.50.68"
|
|
PASS = "Xiao4669805"
|
|
LOCAL = Path(__file__).resolve().parents[1] / "backend" / "neko" / "browser-launch.sh"
|
|
|
|
|
|
def connect():
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
for i in range(8):
|
|
try:
|
|
c.connect(
|
|
HOST,
|
|
22,
|
|
"root",
|
|
PASS,
|
|
timeout=45,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
banner_timeout=180,
|
|
)
|
|
return c
|
|
except Exception as e:
|
|
print("retry", i, e, flush=True)
|
|
time.sleep(2 + i)
|
|
raise SystemExit("ssh fail")
|
|
|
|
|
|
def run(c, cmd, t=240):
|
|
print("\n=====", cmd[:90].replace("\n", " "), flush=True)
|
|
_i, o, e = c.exec_command(cmd, timeout=t)
|
|
out = (o.read() + e.read()).decode("utf-8", "replace")
|
|
print(out[-14000:] if len(out) > 14000 else out, flush=True)
|
|
return out
|
|
|
|
|
|
text = LOCAL.read_text(encoding="utf-8")
|
|
assert "--jitless" in text
|
|
|
|
c = connect()
|
|
sftp = c.open_sftp()
|
|
tmp = "/tmp/browser-launch-jitless-n10.sh"
|
|
with sftp.file(tmp, "wb") as f:
|
|
f.write(text.encode("utf-8"))
|
|
sftp.chmod(tmp, 0o755)
|
|
sftp.close()
|
|
|
|
run(
|
|
c,
|
|
rf"""
|
|
set +e
|
|
export DY_NEKO_NAT1TO1=108.174.50.68
|
|
echo '=== mem/neko ==='
|
|
free -h | head -2
|
|
docker ps -a --filter name=douyinweb-neko --format '{{{{.Names}}}} {{{{.Status}}}}' | sort
|
|
echo '=== timeslot / assign neko10 ==='
|
|
cd /opt/douyinWEB/backend
|
|
set -a; source /etc/douyinweb.env 2>/dev/null || true; set +a
|
|
./.venv/bin/python - <<'PY'
|
|
from app import db, yt_assign_db
|
|
sm = db.get_settings_map()
|
|
print('time_slot_mode', sm.get('youtube_relay_time_slot_mode'))
|
|
print('timeslot_test', sm.get('youtube_relay_timeslot_test'), sm.get('youtube_relay_timeslot_test_group_id'))
|
|
print('relay_enabled', sm.get('youtube_relay_enabled'))
|
|
for g in yt_assign_db.list_groups(include_urls=False, include_secret=False):
|
|
if int(g.get('neko_instance_id') or 0) == 10 or 'neko' in str(g.get('name') or '').lower():
|
|
print('g', g.get('name'), 'neko', g.get('neko_instance_id'), 'cat', g.get('category'),
|
|
'armed', g.get('time_slot_armed'), 'neko_en', g.get('neko_enabled'),
|
|
'yt', (g.get('youtube_channel_id') or '')[:24])
|
|
# all time_slot groups
|
|
for g in yt_assign_db.list_groups(include_urls=False, include_secret=False):
|
|
if str(g.get('category') or '') == 'time_slot' or int(g.get('neko_instance_id') or 0) == 10:
|
|
print('slot', g.get('name'), 'id', g.get('id')[:8], 'neko', g.get('neko_instance_id'),
|
|
'en', g.get('enabled'), 'neko_en', g.get('neko_enabled'))
|
|
PY
|
|
|
|
# ensure neko-10 running (start only)
|
|
docker start douyinweb-neko-10 2>/dev/null || true
|
|
sleep 3
|
|
docker ps --filter name=douyinweb-neko-10 --format '{{{{.Names}}}} {{{{.Status}}}}'
|
|
|
|
# patch mounted inode in-place
|
|
INO=$(docker exec douyinweb-neko-10 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
|
|
[ -n "$MATCH" ] && cat {tmp} > "$MATCH"
|
|
cat {tmp} > /opt/douyinWEB/backend/neko/browser-launch.sh
|
|
chmod 755 /opt/douyinWEB/backend/neko/browser-launch.sh
|
|
docker exec douyinweb-neko-10 grep -n jitless /etc/neko/browser-launch.sh || echo 'STALE_MOUNT'
|
|
|
|
# if stale, overwrite ALL copies under neko dir (same as before)
|
|
for f in /opt/douyinWEB/backend/neko/browser-launch.sh*; do
|
|
[ -f "$f" ] || continue
|
|
cat {tmp} > "$f" || true
|
|
done
|
|
docker exec douyinweb-neko-10 grep -n jitless /etc/neko/browser-launch.sh
|
|
|
|
docker exec douyinweb-neko-10 supervisorctl restart google-chrome
|
|
sleep 12
|
|
docker exec douyinweb-neko-10 supervisorctl status google-chrome
|
|
docker exec douyinweb-neko-10 sh -c 'for p in /proc/[0-9]*; do
|
|
cmd=$(tr "\0" " " < "$p/cmdline" 2>/dev/null)
|
|
case "$cmd" in
|
|
*remote-debugging-port=9222*) echo "$cmd" | tr " " "\n" | grep -E "jitless|js-flags|wasm"; break;;
|
|
esac
|
|
done'
|
|
|
|
# resolve studio URL for group on neko 10
|
|
STUDIO=$(cd /opt/douyinWEB/backend && ./.venv/bin/python - <<'PY'
|
|
from app import yt_assign_db
|
|
url=''
|
|
ycid=''
|
|
for g in yt_assign_db.list_groups(include_urls=False, include_secret=False):
|
|
if int(g.get('neko_instance_id') or 0)==10:
|
|
ycid=str(g.get('youtube_channel_id') or '').strip()
|
|
name=g.get('name')
|
|
print('picked', name, ycid, file=__import__('sys').stderr)
|
|
break
|
|
if ycid:
|
|
url=f'https://studio.youtube.com/channel/{{ycid}}/livestreaming'
|
|
else:
|
|
url='https://studio.youtube.com/'
|
|
print(url)
|
|
PY
|
|
)
|
|
echo STUDIO=$STUDIO
|
|
|
|
docker exec douyinweb-neko-10 python3 -c "
|
|
import json,urllib.request,time,os
|
|
S=os.environ.get('S') or '''$STUDIO'''
|
|
S=S.strip()
|
|
for i in range(40):
|
|
try:
|
|
urllib.request.urlopen('http://127.0.0.1:9222/json/version',timeout=2).read(); print('devtools_ok'); break
|
|
except Exception:
|
|
time.sleep(1)
|
|
else:
|
|
raise SystemExit('no_devtools')
|
|
tabs=json.loads(urllib.request.urlopen('http://127.0.0.1:9222/json/list',timeout=5).read())
|
|
for t in tabs:
|
|
if t.get('type')=='page' and t.get('id'):
|
|
try:
|
|
urllib.request.urlopen('http://127.0.0.1:9222/json/close/'+t['id'], timeout=3).read()
|
|
print('closed', (t.get('url') or '')[:80])
|
|
except Exception as e:
|
|
print('close_err', e)
|
|
req=urllib.request.Request('http://127.0.0.1:9222/json/new?'+S, method='PUT')
|
|
print('open', urllib.request.urlopen(req,timeout=20).read()[:100])
|
|
ok=False
|
|
for i in range(12):
|
|
time.sleep(2)
|
|
tabs=json.loads(urllib.request.urlopen('http://127.0.0.1:9222/json/list',timeout=5).read())
|
|
pages=[t for t in tabs if t.get('type')=='page']
|
|
for t in pages:
|
|
print('t%s' % i, (t.get('title') or '')[:70], '|', (t.get('url') or '')[:110])
|
|
titles=' '.join((t.get('title') or '') for t in pages)
|
|
urls=' '.join((t.get('url') or '') for t in pages)
|
|
bad=('Snap' in titles) or ('SIGILL' in titles) or ('chrome-error' in urls) or (\"Can't open\" in titles)
|
|
good=('studio.youtube.com' in urls) and (not bad)
|
|
if good:
|
|
print('STUDIO_OK'); ok=True; break
|
|
if not ok:
|
|
print('STUDIO_STILL_BAD')
|
|
"
|
|
|
|
# also ensure other RUNNING nekos have jitless visible (restart chrome only if missing)
|
|
for name in $(docker ps --filter name=douyinweb-neko --format '{{{{.Names}}}}'); do
|
|
if docker exec "$name" grep -q jitless /etc/neko/browser-launch.sh 2>/dev/null; then
|
|
echo OK_FLAGS_$name
|
|
else
|
|
echo FIX_FLAGS_$name
|
|
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* | awk -v i="$ino" '$1==i{{print $NF; exit}}')
|
|
[ -n "$match" ] && cat {tmp} > "$match"
|
|
docker exec "$name" supervisorctl restart google-chrome || true
|
|
fi
|
|
done
|
|
|
|
dmesg -T 2>/dev/null | grep -i 'invalid opcode' | tail -3
|
|
curl -sk -o /dev/null -w 'neko10:%{{http_code}}\n' https://dy.nomadro.live/neko/10/
|
|
""",
|
|
)
|
|
|
|
c.close()
|
|
print("DONE")
|