81 lines
3.0 KiB
Python
81 lines
3.0 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""Fix VPS Neko open URL: set DY_PUBLIC_BASE_URL + deploy youtube_neko.py."""
|
|
import sys
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
LOCAL = Path(__file__).resolve().parents[1]
|
|
SRC = LOCAL / "backend/app/youtube_neko.py"
|
|
|
|
DROPIN = """[Service]
|
|
Environment=DY_PUBLIC_BASE_URL=https://dylive.nomadro.com
|
|
Environment=DY_INSTALL_SHAPE=vps
|
|
Environment=DY_NEKO_HTTP_BIND=127.0.0.1
|
|
"""
|
|
|
|
|
|
def main() -> None:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=40, allow_agent=False, look_for_keys=False)
|
|
sftp = c.open_sftp()
|
|
with sftp.file("/tmp/youtube_neko.py.urlfix", "wb") as f:
|
|
f.write(SRC.read_bytes())
|
|
with sftp.file("/tmp/dylive_public_base.conf", "wb") as f:
|
|
f.write(DROPIN.encode())
|
|
sftp.close()
|
|
|
|
remote = r"""
|
|
set -e
|
|
mkdir -p /etc/systemd/system/douyinweb-api.service.d
|
|
# in-place for app file
|
|
cat /tmp/youtube_neko.py.urlfix > /opt/douyinWEB/backend/app/youtube_neko.py
|
|
sed -i 's/\r$//' /opt/douyinWEB/backend/app/youtube_neko.py
|
|
# drop-in for public base (idempotent overwrite)
|
|
cat /tmp/dylive_public_base.conf > /etc/systemd/system/douyinweb-api.service.d/public-base.conf
|
|
systemctl daemon-reload
|
|
systemctl restart douyinweb-api
|
|
sleep 3
|
|
systemctl is-active douyinweb-api
|
|
cd /opt/douyinWEB/backend
|
|
PY=python3; [ -x .venv/bin/python ] && PY=.venv/bin/python
|
|
# verify under systemd env
|
|
systemctl show douyinweb-api -p Environment --value | tr ' ' '\n' | grep -E 'DY_PUBLIC|DY_INSTALL|DY_NEKO_HTTP' || true
|
|
$PY - <<'PY'
|
|
import os, sys
|
|
# mimic systemd env for check
|
|
os.environ.setdefault('DY_PUBLIC_BASE_URL','https://dylive.nomadro.com')
|
|
os.environ.setdefault('DY_INSTALL_SHAPE','vps')
|
|
os.environ.setdefault('DY_NEKO_HTTP_BIND','127.0.0.1')
|
|
sys.path.insert(0,'.')
|
|
# reload settings
|
|
import importlib
|
|
from app import config
|
|
importlib.reload(config)
|
|
from app import youtube_neko
|
|
importlib.reload(youtube_neko)
|
|
print('physical_dual', youtube_neko._physical_dual_edge())
|
|
print('preferred', youtube_neko.preferred_neko_public_base())
|
|
print('studio6', youtube_neko.public_studio_url(6))
|
|
print('studio8', youtube_neko.public_studio_url(8))
|
|
PY
|
|
# live API check
|
|
curl -sS -m 8 -b /tmp/cj -c /tmp/cj -X POST https://dylive.nomadro.com/api/auth/login \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{"username":"hackrobot","password":"Xiao4669805@"}' >/dev/null
|
|
curl -sS -m 8 -b /tmp/cj https://dylive.nomadro.com/api/youtube/assign/groups | \
|
|
python3 -c "import sys,json; d=json.load(sys.stdin); gs=d.get('groups') or d;
|
|
[print(g.get('name'), g.get('neko_instance_id'), g.get('neko_local_studio_url') or g.get('neko_studio_url')) for g in gs if int(g.get('neko_instance_id') or 0) in (6,7,8) or 'nomad' in str(g.get('name') or '').lower()]"
|
|
"""
|
|
_i, o, e = c.exec_command(remote, timeout=120)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"))
|
|
c.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|