Capture frames upload to SeaweedFS; active sessions show covers with enlarge preview. Co-authored-by: Cursor <cursoragent@cursor.com>
247 lines
6.6 KiB
Python
247 lines
6.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Install SeaweedFS + deploy cover/S3/lightbox updates to VPS."""
|
|
from __future__ import annotations
|
|
|
|
import paramiko
|
|
|
|
HOST = "107.173.30.245"
|
|
USER = "root"
|
|
PASSWORD = "Xiao4669805"
|
|
APP = "/opt/douyinWEB"
|
|
GIT = "https://eric:Xiao4669805@gitea.dsx2020.com/eric/douyinWEB.git"
|
|
S3_PORT = 8333
|
|
ACCESS = "douyin"
|
|
SECRET = "douyinweb_s3_2026"
|
|
BUCKET = "douyin-covers"
|
|
WEED_VER = "3.80"
|
|
|
|
|
|
def run(c: paramiko.SSHClient, cmd: str, timeout: int = 900) -> tuple[int, str]:
|
|
print(f"\n$ {cmd[:240]}", flush=True)
|
|
_, out, _ = 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[-5000:], flush=True)
|
|
print(f"[exit {code}]", flush=True)
|
|
return code, text
|
|
|
|
|
|
def main() -> None:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(HOST, 22, USER, PASSWORD, timeout=40, allow_agent=False, look_for_keys=False)
|
|
print("connected", flush=True)
|
|
|
|
# --- SeaweedFS ---
|
|
run(
|
|
c,
|
|
f"""
|
|
set -e
|
|
mkdir -p /opt/seaweedfs /data/seaweed/master /data/seaweed/volume /data/seaweed/filer /etc/seaweedfs
|
|
if [ ! -x /opt/seaweedfs/weed ]; then
|
|
cd /tmp
|
|
curl -fsSL -o weed.tgz "https://github.com/seaweedfs/seaweedfs/releases/download/{WEED_VER}/linux_amd64.tar.gz"
|
|
tar -xzf weed.tgz -C /opt/seaweedfs weed
|
|
chmod +x /opt/seaweedfs/weed
|
|
rm -f weed.tgz
|
|
fi
|
|
/opt/seaweedfs/weed version || true
|
|
|
|
cat >/etc/seaweedfs/s3.json <<'EOF'
|
|
{{
|
|
"identities": [
|
|
{{
|
|
"name": "douyin",
|
|
"credentials": [
|
|
{{"accessKey": "{ACCESS}", "secretKey": "{SECRET}"}}
|
|
],
|
|
"actions": ["Admin", "Read", "Write", "List", "Tagging"]
|
|
}}
|
|
]
|
|
}}
|
|
EOF
|
|
|
|
cat >/etc/systemd/system/seaweed-master.service <<'EOF'
|
|
[Unit]
|
|
Description=SeaweedFS Master
|
|
After=network.target
|
|
[Service]
|
|
ExecStart=/opt/seaweedfs/weed master -ip=127.0.0.1 -port=9333 -mdir=/data/seaweed/master
|
|
Restart=always
|
|
RestartSec=2
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
cat >/etc/systemd/system/seaweed-volume.service <<'EOF'
|
|
[Unit]
|
|
Description=SeaweedFS Volume
|
|
After=network.target seaweed-master.service
|
|
Requires=seaweed-master.service
|
|
[Service]
|
|
ExecStart=/opt/seaweedfs/weed volume -mserver=127.0.0.1:9333 -ip=127.0.0.1 -port=8080 -dir=/data/seaweed/volume -max=100
|
|
Restart=always
|
|
RestartSec=2
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
cat >/etc/systemd/system/seaweed-filer.service <<'EOF'
|
|
[Unit]
|
|
Description=SeaweedFS Filer
|
|
After=network.target seaweed-master.service seaweed-volume.service
|
|
[Service]
|
|
ExecStart=/opt/seaweedfs/weed filer -master=127.0.0.1:9333 -ip=127.0.0.1 -port=8888 -defaultReplicaPlacement=000
|
|
Restart=always
|
|
RestartSec=2
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
cat >/etc/systemd/system/seaweed-s3.service <<'EOF'
|
|
[Unit]
|
|
Description=SeaweedFS S3 API
|
|
After=network.target seaweed-filer.service
|
|
Requires=seaweed-filer.service
|
|
[Service]
|
|
ExecStart=/opt/seaweedfs/weed s3 -filer=127.0.0.1:8888 -ip.bind=0.0.0.0 -port={S3_PORT} -config=/etc/seaweedfs/s3.json
|
|
Restart=always
|
|
RestartSec=2
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
systemctl daemon-reload
|
|
systemctl enable seaweed-master seaweed-volume seaweed-filer seaweed-s3
|
|
systemctl restart seaweed-master
|
|
sleep 2
|
|
systemctl restart seaweed-volume
|
|
sleep 2
|
|
systemctl restart seaweed-filer
|
|
sleep 2
|
|
systemctl restart seaweed-s3
|
|
sleep 3
|
|
systemctl is-active seaweed-master seaweed-volume seaweed-filer seaweed-s3
|
|
ss -lntp | grep -E ':9333|:8080|:8888|:{S3_PORT}' || true
|
|
""".strip(),
|
|
timeout=300,
|
|
)
|
|
|
|
# create bucket via weed shell / s3 api with aws cli or python
|
|
run(
|
|
c,
|
|
f"""
|
|
set -e
|
|
pip3 install -q boto3 || true
|
|
python3 - <<'PY'
|
|
import boto3
|
|
from botocore.client import Config
|
|
c=boto3.client('s3', endpoint_url='http://127.0.0.1:{S3_PORT}',
|
|
aws_access_key_id='{ACCESS}', aws_secret_access_key='{SECRET}',
|
|
region_name='us-east-1', config=Config(signature_version='s3v4', s3={{'addressing_style':'path'}}))
|
|
try:
|
|
c.create_bucket(Bucket='{BUCKET}')
|
|
print('bucket created')
|
|
except Exception as e:
|
|
print('bucket', e)
|
|
print(c.list_buckets())
|
|
PY
|
|
""".strip(),
|
|
)
|
|
|
|
# pull app + deps + build
|
|
run(
|
|
c,
|
|
f"""
|
|
set -e
|
|
cd {APP}
|
|
git remote set-url origin '{GIT}'
|
|
git fetch origin
|
|
git reset --hard origin/main
|
|
|
|
# next rewrite stay on 8014
|
|
cat > frontend/next.config.mjs <<'EOF'
|
|
/** @type {{import('next').NextConfig}} */
|
|
const nextConfig = {{
|
|
reactStrictMode: true,
|
|
async rewrites() {{
|
|
return [
|
|
{{ source: "/api/:path*", destination: "http://127.0.0.1:8014/api/:path*" }},
|
|
{{ source: "/covers/:path*", destination: "http://127.0.0.1:8014/covers/:path*" }},
|
|
];
|
|
}},
|
|
}};
|
|
export default nextConfig;
|
|
EOF
|
|
|
|
cd backend
|
|
. .venv/bin/activate
|
|
pip install -r requirements.txt
|
|
python - <<'PY'
|
|
from app import db
|
|
db.init_db()
|
|
db.update_settings_map({{"capture_cover_on_start": True}})
|
|
print('capture_cover_on_start', db.get_settings_map().get('capture_cover_on_start'))
|
|
PY
|
|
|
|
# inject SeaweedFS env into api unit
|
|
cat >/etc/systemd/system/douyinweb-api.service <<'EOF'
|
|
[Unit]
|
|
Description=DouyinWEB FastAPI
|
|
After=network.target douyinweb-pb.service seaweed-s3.service
|
|
|
|
[Service]
|
|
Type=simple
|
|
WorkingDirectory={APP}/backend
|
|
Environment=DY_PB_URL=http://127.0.0.1:8092
|
|
Environment=DY_S3_ENABLED=true
|
|
Environment=DY_S3_ENDPOINT=http://127.0.0.1:{S3_PORT}
|
|
Environment=DY_S3_PUBLIC_BASE=http://{HOST}:{S3_PORT}
|
|
Environment=DY_S3_ACCESS_KEY={ACCESS}
|
|
Environment=DY_S3_SECRET_KEY={SECRET}
|
|
Environment=DY_S3_BUCKET={BUCKET}
|
|
Environment=DY_S3_REGION=us-east-1
|
|
ExecStart={APP}/backend/.venv/bin/python -m uvicorn app.main:app --host 0.0.0.0 --port 8014
|
|
Restart=always
|
|
RestartSec=3
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
cd {APP}/frontend
|
|
npm install --no-fund --no-audit
|
|
npm run build
|
|
|
|
systemctl daemon-reload
|
|
systemctl restart douyinweb-api douyinweb-web
|
|
sleep 6
|
|
systemctl is-active douyinweb-api douyinweb-web seaweed-s3
|
|
curl -s --max-time 10 http://127.0.0.1:8014/api/health | head -c 400
|
|
echo
|
|
curl -s -o /dev/null -w 'web:%{{http_code}}\\n' --max-time 15 http://127.0.0.1:4014/
|
|
""".strip(),
|
|
timeout=1200,
|
|
)
|
|
|
|
# backfill covers for active rooms
|
|
run(
|
|
c,
|
|
"""
|
|
set -e
|
|
curl -s --max-time 300 -X POST http://127.0.0.1:8014/api/sessions/active/recapture-covers
|
|
echo
|
|
curl -s --max-time 10 http://127.0.0.1:8014/api/sessions/active | python3 -c "import sys,json; d=json.load(sys.stdin); print('active', d.get('total'));
|
|
[print(s.get('anchor_name'), s.get('cover_url','')[:80]) for s in (d.get('sessions') or [])[:8]]"
|
|
""".strip(),
|
|
timeout=400,
|
|
)
|
|
|
|
c.close()
|
|
print(f"\nUI http://{HOST}:4014/", flush=True)
|
|
print(f"S3 http://{HOST}:{S3_PORT}/{BUCKET}/", flush=True)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|