Skip to content

fix: 中断时恢复旧控制面板#5224

Open
eyaeya wants to merge 1 commit into
vernesong:devfrom
eyaeya:net/dashboard-signal-restore
Open

fix: 中断时恢复旧控制面板#5224
eyaeya wants to merge 1 commit into
vernesong:devfrom
eyaeya:net/dashboard-signal-restore

Conversation

@eyaeya

@eyaeya eyaeya commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Dependency chain

推荐合并顺序:本 PR 基于已合入的 #5193#5193 已解决 dashboard 下载校验、staging 安装和失败回滚;本 PR 只补信号中断窗口。

问题现象

控制面板更新时,如果进程在旧目录已移动到 .openclash_dashboard_old.$$、新目录尚未完成落位和校验之间收到 HUP / INT / TERM,目标 dashboard 目录可能暂时或永久缺失,只留下隐藏旧目录或 staging 目录。

根因

#5193 的普通失败路径会调用 restore_old_dashboard,但脚本没有 signal trap。外部中断不会走普通错误分支,因而不会恢复旧 dashboard 或清理 staging 目录。

证据

  • openclash_download_dashboard.sh 先把现有 TARGET_FILE_DIR 移到 .openclash_dashboard_old.$$,随后再把 .openclash_dashboard_new.$$ 移回目标目录。
  • 普通失败路径有 rollback,但 HUP / INT / TERM 不会进入该路径。
  • 新增测试用受控 mv wrapper 在旧目录移动成功后发送 TERM,验证脚本返回中断状态、旧 index.html 被恢复、.openclash_dashboard_* staging 目录被清理。

修复方案

  • 增加 DASHBOARD_REPLACE_STARTED 标志,只在旧目录替换窗口开启后允许恢复旧 dashboard。
  • HUP / INT / TERM 增加 trap:恢复旧目录、清理临时文件、释放锁并退出。
  • 成功安装并校验新目录后清零恢复标志,避免已经验证的新面板被误回滚。

为什么没有扩大修复范围

没有修改 #5193 已合入的目录完整性校验、304 复验、staging 路径或下载逻辑。trap 早于替换窗口不会删除目标目录;只有确认旧目录已进入 .old.$$ 窗口后才尝试恢复。

与已有开启态 PR 的关系

验证命令和结果

均已通过:

bash -n luci-app-openclash/root/usr/share/openclash/*.sh
bash -n tests/*.sh
tests/openclash_download_dashboard_test.sh
for t in tests/*.sh; do "$t"; done
git diff --check
rg -n '^(<<<<<<<|=======|>>>>>>>)' luci-app-openclash/root/usr/share/openclash/openclash_download_dashboard.sh tests/openclash_download_dashboard_test.sh

最后一条无命中。

剩余风险

未做 live router 验证。该补丁只处理脚本进程收到常见终止信号的情况;断电、内核级强制 kill 等无法由 shell trap 恢复。

@eyaeya

eyaeya commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

2026-07-08 最新上游覆盖复核与范围收窄

本轮按最新 dev 复核后,结论是:#5193 已经合入 dashboard 下载校验、staging 安装和普通失败回滚;但上游仍没有覆盖本 PR 处理的 HUP / INT / TERM 中断窗口。因此本 PR 不关闭,也不需要做 merge conflict 修复;当前 GitHub 状态为 MERGEABLE/CLEAN

执行计划与本次更新:

  1. 先确认目标是否已由上游解决:普通失败回滚已在上游,signal trap 仍缺失。
  2. 收窄实现边界:保留上游已有的 restore_old_dashboard 普通回滚语义,只在 signal handler 内根据 DASHBOARD_REPLACE_STARTED 判断是否需要恢复旧目录。
  3. 继续只覆盖旧 dashboard 已移动、新 dashboard 尚未完成落位/校验时被中断的窗口;不重写 fix: 校验控制面板更新结果 #5193 已有的下载校验、staging 安装和普通失败回滚。

已推送:

  • 新 head:2e3cbfe104b1470d5934208caf5c2838b28c650b

验证:

bash -n luci-app-openclash/root/usr/share/openclash/*.sh
bash -n tests/openclash_download_dashboard_test.sh
bash tests/openclash_download_dashboard_test.sh
git diff --check origin/dev...HEAD
rg -n '^(<<<<<<<|=======|>>>>>>>)' luci-app-openclash/root/usr/share/openclash/openclash_download_dashboard.sh tests/openclash_download_dashboard_test.sh

以上均通过。未做 live router 写入验证;本轮只做静态与聚焦脚本验证。

@eyaeya eyaeya force-pushed the net/dashboard-signal-restore branch from 2e3cbfe to 1240c47 Compare July 8, 2026 13:13
@eyaeya

eyaeya commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

补充读回:分支 head 后续更新为 1240c474591abfdeeb001f7e5d9dcead516e0c58;该 head 与上一条说明中的实现树无差异,并已在当前 head 上重新通过同一组聚焦验证:bash -ntests/openclash_download_dashboard_test.shgit diff --check origin/dev...HEAD 和 conflict marker 扫描。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant