86 lines
2.8 KiB
Python
86 lines
2.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Finish dy post-migrate: public_base, neko mem, nginx neko locations."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(
|
|
"108.174.50.68",
|
|
22,
|
|
"root",
|
|
"Xiao4669805",
|
|
timeout=45,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
banner_timeout=120,
|
|
)
|
|
cmd = r"""
|
|
set -euo pipefail
|
|
# Ensure public base in env for neko nginx sync
|
|
grep -q '^DY_PUBLIC_BASE_URL=' /etc/douyinweb.env \
|
|
&& sed -i 's|^DY_PUBLIC_BASE_URL=.*|DY_PUBLIC_BASE_URL=https://dy.nomadro.live|' /etc/douyinweb.env \
|
|
|| echo 'DY_PUBLIC_BASE_URL=https://dy.nomadro.live' >> /etc/douyinweb.env
|
|
grep -q '^PUBLIC_BASE=' /etc/douyinweb.env \
|
|
&& sed -i 's|^PUBLIC_BASE=.*|PUBLIC_BASE=https://dy.nomadro.live|' /etc/douyinweb.env \
|
|
|| echo 'PUBLIC_BASE=https://dy.nomadro.live' >> /etc/douyinweb.env
|
|
|
|
cd /opt/douyinWEB/backend
|
|
set -a; source /etc/douyinweb.env; set +a
|
|
export DY_PUBLIC_BASE_URL=https://dy.nomadro.live
|
|
export DY_NEKO_NAT1TO1=108.174.50.68
|
|
|
|
./.venv/bin/python - <<'PY'
|
|
from app import db
|
|
from app import youtube_neko as yn
|
|
from app import config
|
|
|
|
db.update_settings_map({
|
|
'neko_mem_limit': '1536m',
|
|
})
|
|
print('public', config.settings.public_base_url or '(empty-settings-obj)')
|
|
print('env_public', __import__('os').environ.get('DY_PUBLIC_BASE_URL'))
|
|
# Force regenerate nginx include for /neko/1..4
|
|
r = yn.sync_nginx_proxy(4)
|
|
print('sync_nginx', r)
|
|
inc = '/etc/nginx/conf.d/douyinweb-neko-locations.inc'
|
|
import pathlib
|
|
p = pathlib.Path(inc)
|
|
print('inc_exists', p.exists(), 'lines', len(p.read_text().splitlines()) if p.exists() else 0)
|
|
# count neko locations
|
|
txt = p.read_text() if p.exists() else ''
|
|
print('neko_locs', txt.count('location ^~ /neko/'))
|
|
PY
|
|
|
|
nginx -t
|
|
systemctl reload nginx
|
|
systemctl restart douyinweb-api
|
|
sleep 2
|
|
|
|
# verify
|
|
curl -sS -c /tmp/dyj -b /tmp/dyj -o /tmp/l.json -w 'login:%{http_code}\n' -X POST https://dy.nomadro.live/api/auth/login \
|
|
-H 'Content-Type: application/json' -d '{"username":"hackrobot","password":"Xiao4669805@"}'
|
|
cat /tmp/l.json; echo
|
|
cd /opt/douyinWEB/backend
|
|
./.venv/bin/python - <<'PY'
|
|
from app import db, shorts_oauth
|
|
sm=db.get_settings_map()
|
|
print('cookie', len(str(sm.get('dy_cookie') or '')))
|
|
print('mem', sm.get('neko_mem_limit'))
|
|
print('redirect', sm.get('shorts_oauth_redirect_uri'))
|
|
for p in shorts_oauth.normalize_oauth_profiles(sm.get('shorts_oauth_profiles')):
|
|
print(p['id'], 'ok' if p.get('client_id') and p.get('client_secret') else 'empty', (p.get('label') or '')[:40])
|
|
rooms=db.list_rooms()
|
|
print('rooms', rooms.get('total') if isinstance(rooms, dict) else len(rooms))
|
|
PY
|
|
"""
|
|
_i, o, e = c.exec_command(cmd, timeout=120)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"))
|
|
print("exit", o.channel.recv_exit_status())
|
|
c.close()
|