Files
smart-home-control-system/scripts/stop_web.sh
T
sambu a96cad867e fix(web/cli): 让 --bind 真正生效 + 新增设备表 CSV 导出命令 export
- app_run_web 之前写死 127.0.0.1,--help 却宣传了 --bind;现改为取配置的 bind_addr,
  并在 main.c 把命令行覆盖移到 system_load 之后(原先在 load 前覆盖会被配置文件覆盖掉);
  覆盖只对本次运行生效,退出保存前还原,避免把一次性参数写进 smart_home.ini
- 新增控制台命令 export [路径]:设备表导出 CSV(此前 storage_export_csv 只有接口没有入口)
- 清理 data/ 下旧版本遗留的空目录(config/devices/logs)
- 测试与文档同步:integration.menu 增 export 正向用例与 CSV 落盘断言;README/docs/04 命令表补 export
- 实测:--bind 0.0.0.0 后 ss 显示监听 0.0.0.0:8091,内网 192.168.1.10 访问 200;
  export 生成 data/devices.csv(表头+8 行);ctest 19/19、acceptance 25/25
2026-09-15 00:05:09 +08:00

41 lines
1.3 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
# ============================================================================
# stop_web.sh —— 停止 run_web.sh 启动的网页上位机
#
# 用法: bash scripts/stop_web.sh [端口,默认 8088]
# ============================================================================
set -uo pipefail
PORT="${1:-8088}"
cd "$(dirname "$0")/.." || exit 1
PIDFILE="logs/web_${PORT}.pid"
STOPPED=0
if [ -f "$PIDFILE" ]; then
PID="$(cat "$PIDFILE")"
if kill -0 "$PID" 2>/dev/null; then
kill -INT "$PID" 2>/dev/null || true # 优雅退出:落盘设备表/配置/日志
for _ in 1 2 3 4 5 6 7 8 9 10; do
kill -0 "$PID" 2>/dev/null || break
sleep 0.2
done
kill -0 "$PID" 2>/dev/null && kill -TERM "$PID" 2>/dev/null || true
echo "已停止 PID $PID(端口 $PORT)"
STOPPED=1
fi
rm -f "$PIDFILE"
fi
# 兜底:按端口找进程(仅停止本工程的 smart_home)
if command -v pgrep >/dev/null 2>&1; then
for PID in $(pgrep -f "smart_home --web --port ${PORT}" 2>/dev/null || true); do
kill -INT "$PID" 2>/dev/null || true
echo "已停止 PID $PID(兜底匹配,端口 $PORT)"
STOPPED=1
done
fi
[ "$STOPPED" -eq 0 ] && echo "没有找到端口 $PORT 上运行的本工程网页服务"
exit 0