# -*- coding: utf-8 -*- import sys import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") REMOTE = r""" set -e echo "=== services ===" systemctl is-active douyinweb-api douyinweb-s3 echo "=== cover test before ===" KEY=covers/5d3e14cd-8c13-4b7c-9522-e44dc1cad31e.jpg curl -sS -o /dev/null -w "s3_anon=%{http_code} sz=%{size_download}\n" "http://127.0.0.1:8333/douyin-covers/$KEY" || true echo "=== apply bucket policy ===" cd /opt/douyinWEB/backend timeout 30 .venv/bin/python - <<'PY' import json, urllib.request import boto3 from botocore.client import Config client = boto3.client('s3', endpoint_url='http://127.0.0.1:8333', aws_access_key_id='douyin', aws_secret_access_key='7a9b4d3c9f12bbe404aa2e506ad8e0a4b2ac', region_name='us-east-1', config=Config(signature_version='s3v4', s3={'addressing_style': 'path'})) policy = json.dumps({'Version':'2012-10-17','Statement':[{'Effect':'Allow','Principal':'*','Action':'s3:GetObject','Resource':'arn:aws:s3:::douyin-covers/*'}]}) try: client.put_bucket_policy(Bucket='douyin-covers', Policy=policy) print('policy OK') except Exception as e: print('policy FAIL', e) url='http://127.0.0.1:8333/douyin-covers/covers/5d3e14cd-8c13-4b7c-9522-e44dc1cad31e.jpg' try: with urllib.request.urlopen(url, timeout=8) as r: print('anon', r.status, len(r.read())) except Exception as e: print('anon FAIL', e) PY echo "=== weed shell anonymous (timeout 20s) ===" timeout 20 bash -c "printf 's3.bucket.access -name douyin-covers -user anonymous -access Read,List\nexit\n' | /opt/seaweedfs/weed shell -master=127.0.0.1:9333" 2>&1 | tail -8 || echo weed_shell_timeout echo "=== cover test after ===" curl -sS -o /dev/null -w "s3_anon=%{http_code} sz=%{size_download}\n" "http://127.0.0.1:8333/douyin-covers/$KEY" || true curl -sS -o /dev/null -w "nginx=%{http_code} sz=%{size_download}\n" -k "https://127.0.0.1/douyin-covers/$KEY" -H "Host: dy.nomadro.live" || true echo "=== restart api ===" systemctl restart douyinweb-api sleep 4 systemctl is-active douyinweb-api curl -sS -o /dev/null -w "health=%{http_code}\n" http://127.0.0.1:8014/api/health echo DONE """ c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect("108.174.50.68", 22, "root", "Xiao4669805", timeout=45, allow_agent=False, look_for_keys=False) chan = c.get_transport().open_session() chan.settimeout(90) chan.exec_command(REMOTE) out = b"" while True: if chan.recv_ready(): out += chan.recv(4096) elif chan.exit_status_ready(): while chan.recv_ready(): out += chan.recv(4096) break else: import time time.sleep(0.2) print(out.decode("utf-8", "replace")) c.close()