#!/bin/sh # 观澜 · 启动/停止/重启/状态(Linux / macOS)—— 与 Windows 的 run.bat 等价。 # # 用法: # sh run.sh start 启动全部服务(等价 guanlan.py serve) # sh run.sh stop 停止全部服务 # sh run.sh restart 先停后起 # sh run.sh status 服务状态(端口 / pid / 存活) # sh run.sh status --json 机器可读状态 # sh run.sh help 本说明 # 其余参数原样透传给 guanlan.py,例如: sh run.sh start --only algorithm,web set -e cd "$(dirname "$0")" || exit 1 export PYTHONUTF8=1 pick_python() { if [ -x ".venv/bin/python" ]; then echo ".venv/bin/python"; return 0; fi for c in python3.12 python3.13 python3.11 python3; do p=$(command -v $c 2>/dev/null) && { echo "$p"; return 0; } done return 1 } PY=$(pick_python) || { echo "[X] 找不到 Python 3(.venv 也没有)—— 请先跑 install.sh" >&2 exit 2 } SUB=${1:-help} case "$SUB" in start) shift; exec "$PY" guanlan.py serve "$@" ;; stop) exec "$PY" guanlan.py stop ;; restart) "$PY" guanlan.py stop; exec "$PY" guanlan.py serve ;; status) shift; exec "$PY" guanlan.py status "$@" ;; help|"") cat <<'EOF' 用法: sh run.sh [选项] start 启动全部服务 stop 停止全部服务 restart 先停后起 status 服务状态(--json 为机器可读) help 本说明 EOF ;; *) exec "$PY" guanlan.py "$@" ;; esac