104 lines
2.8 KiB
Python
104 lines
2.8 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""Configure Caddy for dylive + feiniu/s3 SeaweedFS."""
|
||
import paramiko
|
||
|
||
HOST = "107.173.30.245"
|
||
c = paramiko.SSHClient()
|
||
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||
c.connect(HOST, 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False)
|
||
|
||
cmd = r"""
|
||
set -e
|
||
|
||
cp -a /etc/caddy/Caddyfile /etc/caddy/Caddyfile.bak.$(date +%Y%m%d%H%M%S)
|
||
|
||
# Douyin live monitor
|
||
cat >/etc/caddy/sites/dylive.nomadro.com.caddy <<'EOF'
|
||
# DouyinWEB — Next.js + FastAPI + PocketBase
|
||
# https://dylive.nomadro.com
|
||
|
||
dylive.nomadro.com {
|
||
encode gzip
|
||
|
||
handle /api/* {
|
||
reverse_proxy 127.0.0.1:8014
|
||
}
|
||
|
||
handle /covers/* {
|
||
reverse_proxy 127.0.0.1:8014
|
||
}
|
||
|
||
# PocketBase admin / API mirror
|
||
handle /_/* {
|
||
reverse_proxy 127.0.0.1:8092
|
||
}
|
||
|
||
handle {
|
||
reverse_proxy 127.0.0.1:4015
|
||
}
|
||
}
|
||
EOF
|
||
|
||
# SeaweedFS S3 (开源带 F:飞牛 feiniu)
|
||
cat >/etc/caddy/sites/feiniu.nomadro.com.caddy <<'EOF'
|
||
# SeaweedFS S3 API
|
||
# https://feiniu.nomadro.com
|
||
|
||
feiniu.nomadro.com {
|
||
encode gzip
|
||
request_body {
|
||
max_size 200MB
|
||
}
|
||
reverse_proxy 127.0.0.1:8333
|
||
}
|
||
EOF
|
||
|
||
cat >/etc/caddy/sites/s3.nomadro.com.caddy <<'EOF'
|
||
# SeaweedFS S3 API (alias)
|
||
# https://s3.nomadro.com
|
||
|
||
s3.nomadro.com {
|
||
encode gzip
|
||
request_body {
|
||
max_size 200MB
|
||
}
|
||
reverse_proxy 127.0.0.1:8333
|
||
}
|
||
EOF
|
||
|
||
# validate + reload
|
||
caddy validate --config /etc/caddy/Caddyfile
|
||
systemctl reload caddy
|
||
sleep 2
|
||
systemctl is-active caddy
|
||
|
||
# update API public S3 base to feiniu HTTPS
|
||
sed -i 's|Environment=DY_S3_PUBLIC_BASE=.*|Environment=DY_S3_PUBLIC_BASE=https://feiniu.nomadro.com|' /etc/systemd/system/douyinweb-api.service
|
||
grep DY_S3_PUBLIC /etc/systemd/system/douyinweb-api.service
|
||
systemctl daemon-reload
|
||
systemctl restart douyinweb-api
|
||
sleep 4
|
||
|
||
echo '--- https checks ---'
|
||
curl -sI --max-time 20 https://dylive.nomadro.com/ | head -15
|
||
echo
|
||
curl -s -o /dev/null -w 'dylive:%{http_code}\n' --max-time 20 https://dylive.nomadro.com/
|
||
curl -s -o /dev/null -w 'dylive_api:%{http_code}\n' --max-time 20 https://dylive.nomadro.com/api/health
|
||
curl -s --max-time 20 https://dylive.nomadro.com/api/health | head -c 250
|
||
echo
|
||
curl -s -o /dev/null -w 'feiniu:%{http_code}\n' --max-time 15 https://feiniu.nomadro.com/
|
||
curl -s -o /dev/null -w 's3:%{http_code}\n' --max-time 15 https://s3.nomadro.com/
|
||
|
||
SID=$(curl -s https://dylive.nomadro.com/api/sessions/active | python3 -c "import sys,json; d=json.load(sys.stdin); ss=d.get('sessions') or []; print(next((x['id'] for x in ss if x.get('cover_url')), ''))")
|
||
echo SID=$SID
|
||
if [ -n "$SID" ]; then
|
||
curl -s -o /dev/null -w 'cover:%{http_code} size:%{size_download}\n' --max-time 20 "https://dylive.nomadro.com/api/sessions/$SID/cover"
|
||
fi
|
||
"""
|
||
_, o, _ = c.exec_command(cmd, timeout=180, get_pty=True)
|
||
print(o.read().decode("utf-8", errors="replace")[-6000:])
|
||
c.close()
|
||
print("\nhttps://dylive.nomadro.com/")
|
||
print("https://feiniu.nomadro.com/ (SeaweedFS S3)")
|
||
print("https://s3.nomadro.com/ (S3 alias)")
|