Files
FinDataHub/Scripts/bin/mysql_toggle.sh
T
FinDataHub 11d36d1c1e fix(repo): 修正 Scripts 目录索引大小写并补齐未入库脚本
问题
- 索引中该目录记为小写 `scripts/`,工作区实为 `Scripts/`。因 core.ignorecase=true,
  本地 `git diff -- Scripts/bin/x.py` 会**静默返回空**(看似无改动),
  且在大小写敏感环境(Linux CI / Docker 挂载)会检出 `scripts/`,
  与全仓所有 `Scripts/...` 引用不匹配。
- 该目录此前 10 个脚本(check_python_version.py、perf_snapshot.py、
  install_collector_launchd.py、mysql_toggle.sh 等)从未入库,
  而 CI 第 31 行正调用 `Scripts/bin/check_python_version.py --strict` ——
  全新检出必然失败。

改动
- 索引路径统一为 `Scripts/`(工作区文件未移动,仅索引改名)。
- 补齐上述 10 个未跟踪脚本及其测试。

影响
- 修正前索引 35 条(全为小写路径),修正后 45 条。
2026-09-18 22:37:32 +08:00

64 lines
2.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.
#!/bin/bash
# ═══════════════════════════════════════════════════════════════
# mysql_toggle.sh - MySQL 按需启停工具(P2-8)
#
# 注意:仅建议在「采集器已切换为 launchd 批处理模式」(P2-7)后使用,
# 因为常驻采集器 / App 同步功能需要 MySQL 在线。批处理模式下采集是
# 短时任务,可在采集前 start、采集后 stop,空闲时段 MySQL 不驻留。
#
# 用法:
# mysql_toggle.sh start 启动 MySQL(brew services 或 mysql.server)
# mysql_toggle.sh stop 停止 MySQL
# mysql_toggle.sh status 查看状态
# ═══════════════════════════════════════════════════════════════
set -u
CMD="${1:-status}"
# 优先 brew services(macOS 常见安装方式)
brew_manage() {
if command -v brew >/dev/null 2>&1; then
brew services "$1" mysql 2>/dev/null
return $?
fi
return 1
}
# 回退 mysql.server(手动安装/端口安装)
mysqlserver_manage() {
local MYSQL_SERVER
for c in /usr/local/mysql/bin/mysql.server /opt/homebrew/opt/mysql/bin/mysql.server; do
if [ -x "$c" ]; then MYSQL_SERVER="$c"; break; fi
done
if [ -n "${MYSQL_SERVER:-}" ]; then
"$MYSQL_SERVER" "$1"
return $?
fi
return 1
}
case "$CMD" in
start|stop)
echo "[mysql-toggle] $CMD ..."
if brew_manage "$CMD"; then
echo "[mysql-toggle] brew services $CMD ok"
elif mysqlserver_manage "$CMD"; then
echo "[mysql-toggle] mysql.server $CMD ok"
else
echo "[mysql-toggle] 无法自动管理 MySQL,请手动启停" >&2
exit 1
fi
;;
status)
if command -v mysqladmin >/dev/null 2>&1 && mysqladmin ping >/dev/null 2>&1; then
echo "MySQL: 运行中"
else
echo "MySQL: 未运行"
fi
;;
*)
echo "用法: mysql_toggle.sh {start|stop|status}"
exit 1
;;
esac