77 lines
2.1 KiB
Python
77 lines
2.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Ship cover retention to dy as well; verify both."""
|
|
from __future__ import annotations
|
|
|
|
import hashlib
|
|
import sys
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
ROOT = Path(r"c:\Users\admin\Desktop\douyinWEB")
|
|
PASS = "Xiao4669805"
|
|
FILES = [
|
|
"backend/app/s3_storage.py",
|
|
"backend/app/clip_retention.py",
|
|
"backend/app/db.py",
|
|
]
|
|
|
|
|
|
def connect(host):
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
for i in range(6):
|
|
try:
|
|
c.connect(host, 22, "root", PASS, timeout=30, allow_agent=False, look_for_keys=False)
|
|
return c
|
|
except Exception as e:
|
|
print(host, e, flush=True)
|
|
time.sleep(1 + i)
|
|
raise SystemExit(f"fail {host}")
|
|
|
|
|
|
def put_all(c):
|
|
sftp = c.open_sftp()
|
|
for rel in FILES:
|
|
data = (ROOT / rel.replace("/", "\\")).read_bytes()
|
|
h = hashlib.sha256(data).hexdigest()[:12]
|
|
remote = f"/opt/douyinWEB/{rel}"
|
|
with sftp.file(remote, "wb") as f:
|
|
f.write(data)
|
|
print(f" {h} {rel}", flush=True)
|
|
sftp.close()
|
|
|
|
|
|
def apply(host, name):
|
|
print(f"\n=== {name} {host} ===", flush=True)
|
|
c = connect(host)
|
|
put_all(c)
|
|
cmd = r"""
|
|
set -e
|
|
cd /opt/douyinWEB/backend
|
|
./.venv/bin/python - <<'PY'
|
|
from app import db
|
|
db.update_settings_map({"covers_s3_keep_days": 2})
|
|
print("covers_s3_keep_days=", db.get_settings_map().get("covers_s3_keep_days"))
|
|
from app.clip_retention import disk_ok_for_record, disk_free_gb
|
|
print("free_gb=", round(disk_free_gb(),2), "disk_ok=", disk_ok_for_record())
|
|
PY
|
|
systemctl restart douyinweb-api
|
|
sleep 2
|
|
echo api=$(systemctl is-active douyinweb-api)
|
|
df -h / | awk 'NR==2{print}'
|
|
"""
|
|
_i, o, e = c.exec_command(cmd, timeout=90)
|
|
print(o.read().decode("utf-8", "replace"), flush=True)
|
|
err = e.read().decode("utf-8", "replace")
|
|
if err.strip():
|
|
print("[stderr]", err[:500], flush=True)
|
|
c.close()
|
|
|
|
|
|
apply("107.173.30.245", "dylive")
|
|
apply("108.174.50.68", "dy")
|
|
print("BOTH_DONE", flush=True)
|