# -*- coding: utf-8 -*- """Force restart douyinWEB services on VPS.""" import paramiko HOST = "107.173.30.245" PORT = 22 USER = "root" PASSWORD = "Xiao4669805" APP = "/opt/douyinWEB" def run(c, cmd, timeout=180): print(f"\n$ {cmd[:180]}", flush=True) _, out, err = c.exec_command(cmd, timeout=timeout, get_pty=True) text = out.read().decode("utf-8", errors="replace") code = out.channel.recv_exit_status() print(text[-4000:], flush=True) print(f"[exit {code}]", flush=True) return code, text def main(): c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect(HOST, port=PORT, username=USER, password=PASSWORD, timeout=30, allow_agent=False, look_for_keys=False) print("connected", flush=True) run( c, """ set +e # kill by port for p in 3000 8000 8090; do fuser -k ${p}/tcp 2>/dev/null || true done pkill -9 -f 'pocketbase serve' || true pkill -9 -f 'uvicorn app.main:app' || true pkill -9 -f 'uvicorn' || true pkill -9 -f 'next start' || true pkill -9 -f 'next-server' || true sleep 3 ss -lntp | grep -E ':3000|:8000|:8090' || echo 'ports free' """.strip(), ) run( c, f""" set -e cd {APP} git remote set-url origin 'https://eric:Xiao4669805@gitea.dsx2020.com/eric/douyinWEB.git' git fetch origin git reset --hard origin/main test -f backend/data/monitor.db test -x pb/pocketbase || (cd pb && curl -L -o pb.zip https://github.com/pocketbase/pocketbase/releases/download/v0.25.8/pocketbase_0.25.8_linux_amd64.zip && unzip -o pb.zip pocketbase && chmod +x pocketbase && rm -f pb.zip) test -x backend/.venv/bin/python test -d frontend/.next mkdir -p logs nohup ./pb/pocketbase serve --http=0.0.0.0:8090 > logs/pb.log 2>&1 & echo $! > logs/pb.pid cd backend nohup .venv/bin/python -m uvicorn app.main:app --host 0.0.0.0 --port 8000 > ../logs/api.log 2>&1 & echo $! > ../logs/api.pid cd ../frontend nohup npm run start -- --hostname 0.0.0.0 --port 3000 > ../logs/web.log 2>&1 & echo $! > ../logs/web.pid sleep 6 ss -lntp | grep -E ':3000|:8000|:8090' echo HEALTH curl -s --max-time 10 http://127.0.0.1:8000/api/health echo echo WEB curl -s -o /dev/null -w 'web:%{{http_code}}\\n' --max-time 15 http://127.0.0.1:3000/ echo ROOMS curl -s --max-time 10 'http://127.0.0.1:8000/api/rooms?limit=1' | head -c 300 echo tail -n 15 ../logs/api.log """.strip(), ) c.close() print("\nOK http://107.173.30.245:3000/", flush=True) if __name__ == "__main__": main()