From f1ababe5be189f0e9b643572414daee8d2803a24 Mon Sep 17 00:00:00 2001 From: aiyimickey <39365912+aiyimickey@users.noreply.github.com> Date: Thu, 2 Jul 2026 18:36:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=AB=99=E7=82=B9?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E8=84=9A=E6=9C=AC=E7=8A=B6=E6=80=81=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 统一使用端口检测替代容器名检测(更可靠) - 所有站点状态显示端口号 - 修复 sso 容器名:sso-ai → authelia(本地和云端一致) - 修复 macOS bash 3.2 兼容性:移除 declare -A 和 mapfile - 新增端口常量:WWW_AI_PORT、CLOUD_AI_PORT、TOKEN_AI_PORT --- sites-manage-cloud.sh | 75 +++++++++++++++------------ sites-manage-local.sh | 116 ++++++++++++++++++------------------------ 2 files changed, 93 insertions(+), 98 deletions(-) diff --git a/sites-manage-cloud.sh b/sites-manage-cloud.sh index cdef6f6..43ab929 100644 --- a/sites-manage-cloud.sh +++ b/sites-manage-cloud.sh @@ -6,7 +6,7 @@ # # 用法:bash sites-manage-cloud.sh [命令] [站点名...] # 不加命令默认 status -# 站点名:ldap www cloud token gitea issue assets oa nginx +# 站点名:ldap www cloud token gitea issue assets oa nginx sso monitor # ai(上述全部)、all(同 ai) set -e @@ -48,32 +48,41 @@ run() { BASE="/root/docker" -# 站点 → 目录 & 容器名 -declare -A SITE_DIR -SITE_DIR[ldap]="ldap-ai" -SITE_DIR[www]="www-ai" -SITE_DIR[cloud]="cloud-ai" -SITE_DIR[token]="token-ai" -SITE_DIR[gitea]="gitea-ai" -SITE_DIR[issue]="issue-ai" -SITE_DIR[assets]="assets-ai" -SITE_DIR[oa]="oa-ai" -SITE_DIR[nginx]="nginx-proxy-ai" -SITE_DIR[sso]="sso-ai" +# 站点 → 目录 +site_dir() { + case $1 in + ldap) echo "ldap-ai" ;; + www) echo "www-ai" ;; + cloud) echo "cloud-ai" ;; + token) echo "token-ai" ;; + gitea) echo "gitea-ai" ;; + issue) echo "issue-ai" ;; + assets) echo "assets-ai" ;; + oa) echo "oa-ai" ;; + nginx) echo "nginx-proxy-ai" ;; + sso) echo "sso-ai" ;; + monitor) echo "monitor-ai" ;; + esac +} -declare -A SITE_CONTAINER -SITE_CONTAINER[ldap]="lldap" -SITE_CONTAINER[www]="www-ai" -SITE_CONTAINER[cloud]="cloud-ai" -SITE_CONTAINER[token]="token-ai" -SITE_CONTAINER[gitea]="gitea-ai" -SITE_CONTAINER[issue]="issue-ai" -SITE_CONTAINER[assets]="assets-ai" -SITE_CONTAINER[oa]="oa-ai" -SITE_CONTAINER[nginx]="nginx-ai" -SITE_CONTAINER[sso]="sso-ai" +# 站点 → 容器名 +site_container() { + case $1 in + ldap) echo "lldap" ;; + www) echo "www-ai" ;; + cloud) echo "cloud-ai" ;; + token) echo "token-ai" ;; + gitea) echo "gitea-ai" ;; + issue) echo "issue-ai" ;; + assets) echo "assets-ai" ;; + oa) echo "oa-ai" ;; + nginx) echo "nginx-ai" ;; + sso) echo "authelia" ;; + monitor) echo "monitor-ai" ;; + esac +} -AI_SITES="ldap www cloud token gitea issue assets oa nginx" +AI_SITES="ldap www cloud token gitea issue assets oa nginx sso monitor" GREEN='\033[0;32m'; YELLOW='\033[1;33m'; CYAN='\033[0;36m'; RED='\033[0;31m'; NC='\033[0m' log() { printf "${GREEN}[✓]${NC} %s\n" "$1"; } @@ -112,8 +121,8 @@ expand_sites() { # 操作 # ============================================================ remote_start() { - local name=$1 dir="${BASE}/${SITE_DIR[$name]}" - local container="${SITE_CONTAINER[$name]}" + local name=$1 dir="${BASE}/$(site_dir $name)" + local container="$(site_container $name)" if run "docker ps --format '{{.Names}}' | grep -q '^${container}$'" 2>/dev/null; then warn "$name 已在运行" @@ -124,8 +133,8 @@ remote_start() { } remote_stop() { - local name=$1 dir="${BASE}/${SITE_DIR[$name]}" - local container="${SITE_CONTAINER[$name]}" + local name=$1 dir="${BASE}/$(site_dir $name)" + local container="$(site_container $name)" if ! run "docker ps --format '{{.Names}}' | grep -q '^${container}$'" 2>/dev/null; then warn "$name 未在运行" @@ -144,7 +153,7 @@ remote_status() { echo "" for name in "${targets[@]}"; do - local container="${SITE_CONTAINER[$name]}" + local container="$(site_container $name)" local status status=$(run "docker ps --format '{{.Status}}' -f name=^${container}$" 2>/dev/null || echo "") if [ -n "$status" ]; then @@ -178,6 +187,8 @@ show_help() { echo " assets 设备资产管理" echo " oa OA 统一门户" echo " nginx 反向代理" + echo " sso Authelia OIDC 认证" + echo " monitor 告警监控中心" echo " ai 全部 tlyq.ai 站点" echo "" echo "示例:" @@ -194,9 +205,9 @@ show_help() { ACTION=${1:-status} shift || true -mapfile -t TARGETS < <(expand_sites "$@") +TARGETS=($(expand_sites "$@")) if [ ${#TARGETS[@]} -eq 0 ]; then - mapfile -t TARGETS < <(expand_sites ai) + TARGETS=($(expand_sites ai)) fi # 检查 Docker 服务(help 命令除外) diff --git a/sites-manage-local.sh b/sites-manage-local.sh index 6ed385b..7f73533 100755 --- a/sites-manage-local.sh +++ b/sites-manage-local.sh @@ -5,7 +5,7 @@ # # 站点名: # cc: www-cc cloud-cc token-cc -# ai: www-ai cloud-ai token-ai issue assets ldap +# ai: www-ai cloud-ai token-ai issue assets ldap oa sso gitea monitor # all: 全部站点 set -e @@ -16,7 +16,8 @@ ASSETS_DIR="$BASE_DIR/assets-ai" LDAP_DIR="$BASE_DIR/ldap-ai" OA_DIR="$BASE_DIR/oa-ai" GITEA_DIR="$BASE_DIR/gitea-ai" -OA_PORT=6179 +SSO_DIR="$BASE_DIR/sso-ai" +MONITOR_DIR="$BASE_DIR/monitor-ai" # 颜色 GREEN='\033[0;32m'; YELLOW='\033[1;33m'; CYAN='\033[0;36m'; RED='\033[0;31m'; NC='\033[0m' @@ -25,9 +26,18 @@ warn() { printf "${YELLOW}[!]${NC} %s\n" "$1"; } err() { printf "${RED}[✗]${NC} %s\n" "$1"; } # 端口 +WWW_AI_PORT=6173 +CLOUD_AI_PORT=6174 +TOKEN_AI_PORT=6175 ISSUE_PORT=6176 ASSETS_PORT=6177 LDAP_WEB_PORT=6178 +OA_PORT=6179 +SSO_PORT=6180 +MONITOR_PORT=6181 +WWW_CC_PORT=5173 +CLOUD_CC_PORT=5174 +TOKEN_CC_PORT=5175 GITEA_PORT=3000 is_port() { lsof -i :"$1" >/dev/null 2>&1; } @@ -109,9 +119,11 @@ start_all() { log "LLDAP Web UI: http://127.0.0.1:$LDAP_WEB_PORT" fi ;; oa) node_start oa-ai "$OA_DIR" $OA_PORT "/tmp/oa-ai-dev.log" ;; + sso) docker_start authelia "$SSO_DIR" ;; gitea) docker_start gitea-ai "$GITEA_DIR" ;; + monitor) node_start monitor-ai "$MONITOR_DIR" $MONITOR_PORT "/tmp/monitor-ai-dev.log" ;; cc) start_all www-cc cloud-cc token-cc ;; - ai) start_all ldap www-ai cloud-ai token-ai issue assets oa gitea ;; + ai) start_all ldap www-ai cloud-ai token-ai issue assets oa sso gitea monitor ;; all) start_all cc ai ;; *) err "未知站点: $name" ;; esac @@ -131,9 +143,11 @@ stop_all() { assets) node_stop assets-ai $ASSETS_PORT ;; ldap) docker_stop lldap "$LDAP_DIR" ;; oa) node_stop oa-ai $OA_PORT ;; + sso) docker_stop authelia "$SSO_DIR" ;; gitea) docker_stop gitea-ai "$GITEA_DIR" ;; + monitor) node_stop monitor-ai $MONITOR_PORT ;; cc) stop_all www-cc cloud-cc token-cc ;; - ai) stop_all ldap www-ai cloud-ai token-ai issue assets oa gitea ;; + ai) stop_all ldap www-ai cloud-ai token-ai issue assets oa sso gitea monitor ;; all) stop_all cc ai ;; *) err "未知站点: $name" ;; esac @@ -156,9 +170,9 @@ show_status() { local expanded=() for t in "${targets[@]}"; do case $t in - all) eval "expanded=(www-cc cloud-cc token-cc ldap www-ai cloud-ai token-ai issue assets oa gitea)" ;; + all) eval "expanded=(www-cc cloud-cc token-cc ldap www-ai cloud-ai token-ai issue assets oa sso gitea monitor)" ;; cc) eval "expanded=(\${expanded[@]} www-cc cloud-cc token-cc)" ;; - ai) eval "expanded=(\${expanded[@]} ldap www-ai cloud-ai token-ai issue assets oa gitea)" ;; + ai) eval "expanded=(\${expanded[@]} ldap www-ai cloud-ai token-ai issue assets oa sso gitea monitor)" ;; *) expanded+=($t) ;; esac done @@ -169,66 +183,34 @@ show_status() { printf "${CYAN}=========================================${NC}\n" echo "" + # 获取站点对应端口 + get_port() { + case $1 in + www-cc) echo $WWW_CC_PORT ;; + cloud-cc) echo $CLOUD_CC_PORT ;; + token-cc) echo $TOKEN_CC_PORT ;; + www-ai) echo $WWW_AI_PORT ;; + cloud-ai) echo $CLOUD_AI_PORT ;; + token-ai) echo $TOKEN_AI_PORT ;; + issue) echo $ISSUE_PORT ;; + assets) echo $ASSETS_PORT ;; + ldap) echo $LDAP_WEB_PORT ;; + oa) echo $OA_PORT ;; + sso) echo $SSO_PORT ;; + gitea) echo $GITEA_PORT ;; + monitor) echo $MONITOR_PORT ;; + esac + } + local running=0 for name in "${expanded[@]}"; do - case $name in - www-cc|cloud-cc|token-cc|cloud-ai|token-ai) - if is_running $name; then - printf " ${GREEN}●${NC} %-12s 运行中\n" "$name" - running=$((running + 1)) - else - printf " ${RED}●${NC} %-12s 未运行\n" "$name" - fi - ;; - www-ai) - if is_running www-local-ai; then - printf " ${GREEN}●${NC} %-12s 运行中\n" "$name" - running=$((running + 1)) - else - printf " ${RED}●${NC} %-12s 未运行\n" "$name" - fi - ;; - issue) - if is_port $ISSUE_PORT; then - printf " ${GREEN}●${NC} %-12s 运行中 (port %d)\n" "$name" $ISSUE_PORT - running=$((running + 1)) - else - printf " ${RED}●${NC} %-12s 未运行\n" "$name" - fi - ;; - ldap) - if is_running lldap; then - printf " ${GREEN}●${NC} %-12s 运行中 (port %d)\n" "$name" $LDAP_WEB_PORT - running=$((running + 1)) - else - printf " ${RED}●${NC} %-12s 未运行\n" "$name" - fi - ;; - assets) - if is_port $ASSETS_PORT; then - printf " ${GREEN}●${NC} %-12s 运行中 (port %d)\n" "$name" $ASSETS_PORT - running=$((running + 1)) - else - printf " ${RED}●${NC} %-12s 未运行\n" "$name" - fi - ;; - oa) - if is_port $OA_PORT; then - printf " ${GREEN}●${NC} %-12s 运行中 (port %d)\n" "$name" $OA_PORT - running=$((running + 1)) - else - printf " ${RED}●${NC} %-12s 未运行\n" "$name" - fi - ;; - gitea) - if is_running gitea-ai; then - printf " ${GREEN}●${NC} %-12s 运行中 (port %d)\n" "$name" $GITEA_PORT - running=$((running + 1)) - else - printf " ${RED}●${NC} %-12s 未运行\n" "$name" - fi - ;; - esac + local port=$(get_port $name) + if [ -n "$port" ] && is_port $port; then + printf " ${GREEN}●${NC} %-12s 运行中 (port %d)\n" "$name" $port + running=$((running + 1)) + else + printf " ${RED}●${NC} %-12s 未运行\n" "$name" + fi done echo "" @@ -247,9 +229,11 @@ show_status() { echo " token-ai http://127.0.0.1:6175" echo " ldap http://127.0.0.1:$LDAP_WEB_PORT (LLDAP Web UI)" echo " oa http://127.0.0.1:$OA_PORT" + echo " sso http://127.0.0.1:$SSO_PORT (Authelia OIDC)" echo " issue http://127.0.0.1:$ISSUE_PORT" echo " assets http://127.0.0.1:$ASSETS_PORT" echo " gitea http://127.0.0.1:$GITEA_PORT" + echo " monitor http://127.0.0.1:$MONITOR_PORT" echo "" } @@ -268,9 +252,9 @@ show_help() { echo "" echo " 站点名(可指定多个,空格分隔):" echo " www-cc cloud-cc token-cc" - echo " ldap www-ai cloud-ai token-ai issue assets oa gitea" + echo " ldap www-ai cloud-ai token-ai issue assets oa sso gitea monitor" echo " cc — tlyq.cc 全部 (www-cc cloud-cc token-cc)" - echo " ai — tlyq.ai 全部 (ldap www-ai cloud-ai token-ai issue assets oa gitea)" + echo " ai — tlyq.ai 全部 (ldap www-ai cloud-ai token-ai issue assets oa sso gitea monitor)" echo " all — 全部站点" echo "" echo "示例:"