diff --git a/README.md b/README.md index 10b93ff..41e27f8 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ source activate.sh # 推荐:一键拉起全部服务(含监控守护) ./run.sh all # 薄封装:等价于 ./scripts/service_ctl.sh up all -# 查看状态(含 monitor daemon 状态) -./scripts/service_ctl.sh status +# 查看状态 + 健康检查(含 monitor daemon 状态) +./status.sh # 薄封装:等价于 ./scripts/service_ctl.sh status # 重启指定服务集合(示例:全部) ./restart.sh all # 薄封装:等价于 ./scripts/service_ctl.sh restart all diff --git a/docs/Usage-Guide.md b/docs/Usage-Guide.md index 1926465..6a2fb0c 100644 --- a/docs/Usage-Guide.md +++ b/docs/Usage-Guide.md @@ -249,6 +249,7 @@ python -m http.server 6003 - `./run.sh [all|service...]`:薄封装,直接调用 `./scripts/service_ctl.sh up [all|service...]`。 - `./restart.sh [all|service...]`:薄封装,直接调用 `./scripts/service_ctl.sh restart [all|service...]`。 - `./scripts/stop.sh [all|service...]`:薄封装,直接调用 `./scripts/service_ctl.sh down [all|service...]`。 +- `./status.sh`:薄封装,直接调用 `./scripts/service_ctl.sh status`(包含进程/端口 + HTTP 健康检查结果)。 - `./scripts/service_ctl.sh`:统一控制器,支持 `up/down/start/stop/restart/status/monitor*`(带参数行为完全由此脚本定义)。 ### 2) `service_ctl.sh` 的默认行为 @@ -258,7 +259,7 @@ python -m http.server 6003 - `start`:**必须显式指定** 服务或 `all`(不自动拉起 monitor daemon)。 - `stop`:**必须显式指定** 服务或 `all`;若 monitor daemon 运行会先停止它。 - `restart`:**必须显式指定** 服务或 `all`。 -- `status`(不带服务名):显示全部已知服务状态 + monitor daemon 状态。 +- `status`(不带服务名):显示全部已知服务状态 + monitor daemon 状态,并对支持的服务执行 HTTP/容器级健康检查。 ### 3) 全量服务一键拉起 @@ -276,7 +277,7 @@ python -m http.server 6003 # 一键拉起完整栈(推荐) ./scripts/service_ctl.sh up all # 或 ./run.sh all -# 查看全量状态 +# 查看全量状态 + 健康检查(进程/端口 + HTTP) ./scripts/service_ctl.sh status # 仅重启某个服务 diff --git a/scripts/service_ctl.sh b/scripts/service_ctl.sh index 38d060c..55ce57d 100755 --- a/scripts/service_ctl.sh +++ b/scripts/service_ctl.sh @@ -96,7 +96,6 @@ health_path_for_service() { local service="$1" case "${service}" in backend|indexer|embedding|translator|reranker|tei) echo "/health" ;; - frontend) echo "/" ;; *) echo "" ;; esac } @@ -583,6 +582,8 @@ status_one() { port="$(get_port "${service}")" local running="no" local pid_info="-" + local health="down" + local health_body="" if [ "${service}" = "tei" ]; then local cid @@ -591,8 +592,22 @@ status_one() { if [ -n "${cid}" ]; then running="yes" pid_info="${cid:0:12}" + # TEI: container 级别 running 后再尝试 HTTP /health + local path + path="$(health_path_for_service "${service}")" + if [ -n "${port}" ] && [ -n "${path}" ]; then + if health_body="$(curl -fsS "http://127.0.0.1:${port}${path}" 2>/dev/null)"; then + health="ok" + else + health="fail" + fi + fi + fi + if [ -n "${health_body}" ]; then + printf "%-10s running=%-3s port=%-6s pid=%s health=%-4s body=%s\n" "${service}" "${running}" "${port:--}" "${pid_info}" "${health}" "${health_body}" + else + printf "%-10s running=%-3s port=%-6s pid=%s health=%-4s\n" "${service}" "${running}" "${port:--}" "${pid_info}" "${health}" fi - printf "%-10s running=%-3s port=%-6s pid=%s\n" "${service}" "${running}" "${port:--}" "${pid_info}" return fi @@ -604,7 +619,26 @@ status_one() { pid_info="$(lsof -ti:${port} 2>/dev/null | tr '\n' ',' | sed 's/,$//' || echo "-")" fi - printf "%-10s running=%-3s port=%-6s pid=%s\n" "${service}" "${running}" "${port:--}" "${pid_info}" + if [ "${running}" = "yes" ]; then + local path + path="$(health_path_for_service "${service}")" + if [ -n "${port}" ] && [ -n "${path}" ]; then + if health_body="$(curl -fsS "http://127.0.0.1:${port}${path}" 2>/dev/null)"; then + health="ok" + else + health="fail" + fi + else + # 没有 HTTP 健康检查端点(如 cnclip),运行即可视为 ok + health="ok" + fi + fi + + if [ -n "${health_body}" ]; then + printf "%-10s running=%-3s port=%-6s pid=%s health=%-4s body=%s\n" "${service}" "${running}" "${port:--}" "${pid_info}" "${health}" "${health_body}" + else + printf "%-10s running=%-3s port=%-6s pid=%s health=%-4s\n" "${service}" "${running}" "${port:--}" "${pid_info}" "${health}" + fi } service_is_running() { diff --git a/status.sh b/status.sh new file mode 100644 index 0000000..38d1920 --- /dev/null +++ b/status.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +set -euo pipefail + +cd "$(dirname "$0")" + +./scripts/service_ctl.sh status "$@" + -- libgit2 0.21.2