Files
sso/scripts/local-serve.sh
T
admin 1e2b117218 refactor(paths): 拆 source/ 包层,顶层与 ipass/ipass 对齐
- source/rust   → rust/
- source/conf   → conf/
- source/www    → www/
- source/data-seed → data-seed/
- source/data   → data/
- scripts/ 保留(语义不对应 ipass deploy/)
- /build/ 加入 .gitignore(本机 nginx 源码树)
- README.md 目录树同步 + build 路径 /tmp/sso-build → ./build
- Cargo.toml path 依赖 '../../deps/ipass' → '../deps/ipass'
- CLAUDE.md 同步路径示例

cargo check 通过(52s);release build 通过(1m26s),产物 libsso_gateway.dylib
2026-09-21 15:44:55 +08:00

82 lines
3.2 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# ============================================================================
# 本地起停 SSO 网关(手工联调用,与 scripts/run-local-e2e.sh 同一套配置)
#
# 与 run-local-e2e.sh 的区别:那个跑完就停进程,这个是常驻,
# 用来开着浏览器点管理台、或者手工 curl 端点。
#
# 用法:
# bash scripts/local-serve.sh start # 起(默认)
# bash scripts/local-serve.sh stop # 停
# bash scripts/local-serve.sh restart
#
# 所有凭据来自项目根 .env(不进 git),命令行里不出现任何密钥。
# ============================================================================
set -euo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT="$(cd "$HERE/.." && pwd)"
# shellcheck source=scripts/load-env.sh
. "$HERE/load-env.sh"
NGINX_SRC="${NGINX_SRC:-./build/src/nginx-1.30.4}"
NGINX_BIN="${NGINX_BIN:-$NGINX_SRC/objs/nginx}"
MODULE_DIR="$ROOT/rust/target/release"
if [ -f "$MODULE_DIR/libsso_gateway.dylib" ]; then
MODULE="$MODULE_DIR/libsso_gateway.dylib"
else
MODULE="$MODULE_DIR/libsso_gateway.so"
fi
CONF="/tmp/sso-nginx-test.conf"
PID="/tmp/sso-nginx.pid"
SHELL_PID="/tmp/sso-nginx-shell.pid"
ERR_LOG="/tmp/sso-nginx-error.log"
# 签名密钥 / issuer:缺省值兜底,正常情况都由 .env 提供
export OAUTH_SIGNING_SECRET="${OAUTH_SIGNING_SECRET:-$(openssl rand -hex 32)}"
export OAUTH_ISSUER="${OAUTH_ISSUER:-http://127.0.0.1:18098}"
if [ -n "${OAUTH_COOKIE_DOMAIN:-}" ]; then export OAUTH_COOKIE_DOMAIN; fi
stop() {
[ -f "$PID" ] && kill "$(cat "$PID")" 2>/dev/null || true
[ -f "$SHELL_PID" ] && kill "$(cat "$SHELL_PID")" 2>/dev/null || true
rm -f "$PID" "$SHELL_PID"
echo "stopped"
}
case "${1:-start}" in
stop) stop; exit 0 ;;
restart) stop; sleep 0.5 ;;
start) ;;
*) echo "用法: bash $0 [start|stop|restart]" >&2; exit 2 ;;
esac
[ -x "$NGINX_BIN" ] || { echo "!! nginx 二进制缺失:$NGINX_BIN" >&2; exit 1; }
[ -f "$MODULE" ] || { echo "!! Rust 模块缺失:${MODULE}(先 cargo build --release)" >&2; exit 1; }
[ -f "$CONF" ] || {
# 没现成配置就复用 run-local-e2e.sh 的生成逻辑(它会连带物化种子数据)
echo "## 没有 ${CONF},先跑一次 run-local-e2e.sh 生成配置 ..."
bash "$HERE/run-local-e2e.sh" --keep > /dev/null 2>&1 || true
if [ -f "$PID" ]; then kill "$(cat "$PID")" 2>/dev/null || true; fi
pkill -f "demo-system/app.py" 2>/dev/null || true
[ -f "$CONF" ] || { echo "!! 配置生成失败" >&2; exit 1; }
}
"$NGINX_BIN" -c "$CONF" -g 'daemon off;' -e "$ERR_LOG" > /tmp/sso-nginx-stdout.log 2>&1 &
echo $! > "$SHELL_PID"
for i in $(seq 1 20); do
code="$(curl -s -o /dev/null -w '%{http_code}' "${OAUTH_ISSUER}/.well-known/openid-configuration" || true)"
[ "$code" = "200" ] && break
sleep 0.5
done
code="$(curl -s -o /dev/null -w '%{http_code}' "${OAUTH_ISSUER}/.well-known/openid-configuration" || true)"
if [ "$code" != "200" ]; then
echo "!! 网关未就绪(HTTP ${code}),日志:" >&2; tail -30 "$ERR_LOG" >&2; exit 1
fi
echo "started: $OAUTH_ISSUER (discovery=$code)"
echo " admin: ${ADMIN_USER:-admin} / (口令见 .env 的 ADMIN_PASSWORD)"
echo " 停止: bash $0 stop"