47 lines
2.0 KiB
Python
47 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
|
|
def main() -> int:
|
|
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)
|
|
for cmd, t in [
|
|
("systemctl restart douyinweb-api", 90),
|
|
("sleep 3; systemctl is-active douyinweb-api; curl -sS -m 10 -o /dev/null -w 'health=%{http_code}\\n' http://127.0.0.1:8014/api/health", 40),
|
|
]:
|
|
print("$", cmd, flush=True)
|
|
_, o, e = c.exec_command(cmd, timeout=t)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"), flush=True)
|
|
|
|
py = r"""
|
|
import json,urllib.request,http.cookiejar
|
|
cj=http.cookiejar.CookieJar(); op=urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
|
|
req=urllib.request.Request('http://127.0.0.1:8014/api/auth/login', data=json.dumps({'username':'hackrobot','password':'Xiao4669805@'}).encode(), headers={'Content-Type':'application/json'}, method='POST')
|
|
print('login', op.open(req, timeout=20).status)
|
|
req2=urllib.request.Request('http://127.0.0.1:8014/api/yt-long/settings', data=json.dumps({'yt_long_channel_daily_max': 8}).encode(), headers={'Content-Type':'application/json'}, method='POST')
|
|
r=json.loads(op.open(req2, timeout=40).read())
|
|
print('save', r.get('settings',{}).get('yt_long_channel_daily_max'), r.get('channel_daily_max'))
|
|
st=json.loads(op.open('http://127.0.0.1:8014/api/yt-long/status', timeout=40).read())
|
|
print('status', st.get('settings',{}).get('yt_long_channel_daily_max'), st.get('channel_daily_max'))
|
|
"""
|
|
sftp = c.open_sftp()
|
|
with sftp.file("/tmp/_v_ylq2.py", "w") as f:
|
|
f.write(py)
|
|
sftp.close()
|
|
_, o, e = c.exec_command("/opt/douyinWEB/backend/.venv/bin/python /tmp/_v_ylq2.py", timeout=90)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"), flush=True)
|
|
c.close()
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|