Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP. Co-authored-by: Cursor <cursoragent@cursor.com>
144 lines
5.3 KiB
Python
144 lines
5.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Finish remaining bootstrap steps: S3 bucket, PB admin, BaoTa vhost only."""
|
|
import sys
|
|
import time
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
HOST = "192.227.152.110"
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(HOST, 22, "root", "Leaf448772566", timeout=30, allow_agent=False, look_for_keys=False)
|
|
|
|
|
|
def run(cmd, timeout=120):
|
|
print("\n$", cmd[:120], flush=True)
|
|
_, o, e = c.exec_command(cmd, timeout=timeout, get_pty=True)
|
|
text = (o.read() + e.read()).decode("utf-8", "replace")
|
|
print(text[-4000:], flush=True)
|
|
return o.channel.recv_exit_status(), text
|
|
|
|
|
|
# secrets from first run
|
|
code, env = run("grep -E '^(S3_SECRET|SESSION_SECRET|S3_ACCESS|S3_BUCKET)=' /etc/douyinweb.env")
|
|
vals = dict(line.split("=", 1) for line in env.splitlines() if "=" in line and not line.startswith("["))
|
|
s3_secret = vals.get("S3_SECRET", "")
|
|
s3_access = vals.get("S3_ACCESS", "douyin")
|
|
s3_bucket = vals.get("S3_BUCKET", "douyin-covers")
|
|
print("s3_access", s3_access, "bucket", s3_bucket, "secret_len", len(s3_secret))
|
|
|
|
py = f"""
|
|
import boto3
|
|
from botocore.client import Config
|
|
c=boto3.client('s3', endpoint_url='http://127.0.0.1:8333',
|
|
aws_access_key_id='{s3_access}', aws_secret_access_key='{s3_secret}',
|
|
region_name='us-east-1', config=Config(signature_version='s3v4', s3={{'addressing_style':'path'}}))
|
|
try:
|
|
c.create_bucket(Bucket='{s3_bucket}')
|
|
print('bucket created')
|
|
except Exception as e:
|
|
print('bucket', e)
|
|
print(c.list_buckets())
|
|
"""
|
|
run(f"cd /opt/douyinWEB/backend && .venv/bin/python - <<'PY'\n{py}\nPY")
|
|
run("cd /opt/douyinWEB/pb && ./pocketbase superuser upsert 'dsx2016@ypp.smallzhiyuns.com' 'Leaf448772566'")
|
|
|
|
# nginx vhost using wildcard cert — new files only
|
|
run(
|
|
r"""
|
|
set -e
|
|
DOMAIN=ypp.smallzhiyuns.com
|
|
NGINX=/www/server/nginx/sbin/nginx
|
|
CERT=/www/server/panel/vhost/cert/${DOMAIN}
|
|
mkdir -p "$CERT" /www/wwwroot/${DOMAIN} \
|
|
/www/server/panel/vhost/nginx/proxy/${DOMAIN} \
|
|
/www/server/panel/vhost/nginx/extension/${DOMAIN} \
|
|
/www/server/panel/vhost/nginx/well-known \
|
|
/www/server/panel/vhost/rewrite
|
|
cp -f /root/.acme.sh/*.smallzhiyuns.com_ecc/fullchain.cer "$CERT/fullchain.pem"
|
|
cp -f /root/.acme.sh/*.smallzhiyuns.com_ecc/*.smallzhiyuns.com.key "$CERT/privkey.pem"
|
|
: > /www/server/panel/vhost/nginx/well-known/${DOMAIN}.conf
|
|
: > /www/server/panel/vhost/rewrite/${DOMAIN}.conf
|
|
echo '# placeholder' > /www/server/panel/vhost/nginx/extension/${DOMAIN}/placeholder.conf
|
|
cat >/www/server/panel/vhost/nginx/proxy/${DOMAIN}/douyinweb.conf <<'EOF'
|
|
location ^~ /api/ {
|
|
proxy_pass http://127.0.0.1:8014;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection $connection_upgrade;
|
|
proxy_read_timeout 3600s;
|
|
client_max_body_size 200m;
|
|
}
|
|
location ^~ /covers/ {
|
|
proxy_pass http://127.0.0.1:8014;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
location ^~ /_/ {
|
|
proxy_pass http://127.0.0.1:8092;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
location ^~ /douyin-covers/ {
|
|
proxy_pass http://127.0.0.1:8333;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
client_max_body_size 200m;
|
|
}
|
|
location / {
|
|
proxy_pass http://127.0.0.1:4015;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection $connection_upgrade;
|
|
}
|
|
EOF
|
|
cat >/www/server/panel/vhost/nginx/${DOMAIN}.conf <<EOF
|
|
server
|
|
{
|
|
listen 80;
|
|
listen 443 ssl http2;
|
|
server_name ${DOMAIN};
|
|
index index.html;
|
|
root /www/wwwroot/${DOMAIN};
|
|
client_max_body_size 200m;
|
|
ssl_certificate ${CERT}/fullchain.pem;
|
|
ssl_certificate_key ${CERT}/privkey.pem;
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
|
ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:!MD5;
|
|
ssl_prefer_server_ciphers on;
|
|
error_page 497 https://\$host\$request_uri;
|
|
include /www/server/panel/vhost/nginx/well-known/${DOMAIN}.conf;
|
|
include /www/server/panel/vhost/nginx/proxy/${DOMAIN}/*.conf;
|
|
location ~ \.well-known { allow all; }
|
|
access_log /www/wwwlogs/${DOMAIN}.log;
|
|
error_log /www/wwwlogs/${DOMAIN}.error.log;
|
|
}
|
|
EOF
|
|
$NGINX -t
|
|
$NGINX -s reload
|
|
echo nginx_reloaded
|
|
curl -sS -o /dev/null -w 'local_health:%{http_code}\n' http://127.0.0.1:8014/api/health
|
|
curl -sS -o /dev/null -w 'local_login:%{http_code}\n' http://127.0.0.1:4015/login
|
|
curl -sS -o /dev/null -w 'pub_login:%{http_code}\n' --max-time 20 -H 'Host: ypp.smallzhiyuns.com' http://127.0.0.1/login
|
|
curl -sS -o /dev/null -w 'pub_https:%{http_code}\n' --max-time 20 https://ypp.smallzhiyuns.com/login
|
|
curl -sS --max-time 15 http://127.0.0.1:8014/api/health
|
|
echo
|
|
# existing sites still ok
|
|
curl -sS -o /dev/null -w 'gitea80:%{http_code}\n' --max-time 10 -H 'Host: gitea.dsx2020.com' http://127.0.0.1/
|
|
curl -sS -o /dev/null -w 'miniflux:%{http_code}\n' --max-time 10 -H 'Host: miniflux.smallzhiyuns.com' http://127.0.0.1/
|
|
"""
|
|
)
|
|
|
|
c.close()
|
|
print("FINISH_OK")
|