补充 world geo nginx snippet、OpenAPI/geo 热更新脚本,以及 popadmin package_name 定价补丁,便于运维对齐。 Co-authored-by: Cursor <cursoragent@cursor.com>
64 lines
2.1 KiB
Bash
64 lines
2.1 KiB
Bash
#!/bin/bash
|
|
# Hot-override sparkapi /openapi.yaml with latest spec (no container rebuild / no JWT touch).
|
|
set -euo pipefail
|
|
|
|
SPEC_SRC="${1:-/tmp/openapi.yaml}"
|
|
SPEC_DST=/var/www/sparkapi-docs/openapi.yaml
|
|
NGINX_CONF=/etc/nginx/conf.d/sparkapi-wyrs.conf
|
|
# fallback name used on this host
|
|
if [[ ! -f "$NGINX_CONF" ]]; then
|
|
NGINX_CONF=$(ls /etc/nginx/conf.d/sparkapi*.conf 2>/dev/null | grep -v '\.bak' | head -1)
|
|
fi
|
|
echo "nginx_conf=$NGINX_CONF"
|
|
|
|
install -d -m 755 /var/www/sparkapi-docs
|
|
install -m 644 "$SPEC_SRC" "$SPEC_DST"
|
|
wc -c "$SPEC_DST"
|
|
grep -c squarenovel "$SPEC_DST" || true
|
|
|
|
MARKER='# BEGIN sparkapi-openapi-override'
|
|
if grep -q "$MARKER" "$NGINX_CONF"; then
|
|
echo "nginx override block already present"
|
|
else
|
|
TS=$(date +%Y%m%d%H%M%S)
|
|
cp -a "$NGINX_CONF" "${NGINX_CONF}.bak.openapi.$TS"
|
|
python3 <<PY
|
|
from pathlib import Path
|
|
p = Path("$NGINX_CONF")
|
|
text = p.read_text(encoding="utf-8")
|
|
block = '''
|
|
# BEGIN sparkapi-openapi-override
|
|
# Serve latest OpenAPI without rebuilding spark-server image (embed).
|
|
location = /openapi.yaml {
|
|
default_type application/yaml;
|
|
charset utf-8;
|
|
alias /var/www/sparkapi-docs/openapi.yaml;
|
|
add_header Cache-Control "no-store";
|
|
add_header Access-Control-Allow-Origin "*";
|
|
}
|
|
# END sparkapi-openapi-override
|
|
'''
|
|
needle = " location / {"
|
|
idx = text.find(needle)
|
|
if idx < 0:
|
|
raise SystemExit("location / not found in " + str(p))
|
|
# insert before the last occurrence of location / inside sparkapi server (HTTPS)
|
|
# Prefer inserting before location / that has proxy_pass spark_http
|
|
pos = text.rfind(" location / {\n proxy_pass http://spark_http;")
|
|
if pos < 0:
|
|
pos = text.rfind(needle)
|
|
text2 = text[:pos] + block + "\n" + text[pos:]
|
|
p.write_text(text2, encoding="utf-8")
|
|
print("inserted openapi override")
|
|
PY
|
|
fi
|
|
|
|
nginx -t
|
|
systemctl reload nginx
|
|
echo RELOAD_OK
|
|
|
|
# verify via local loopback Host header if possible
|
|
curl -sk -o /tmp/oa.out -w "https_loop:%{http_code} size:%{size_download}\n" -H "Host: sparkapi.wyrs365.com" https://127.0.0.1:8443/openapi.yaml || true
|
|
grep -c squarenovel /tmp/oa.out || true
|
|
head -c 80 /tmp/oa.out; echo
|