feat: 更新服务 — ZIP下载/备份/回滚/重启

UpdateService:
- 分支感知: 从 base_config 读取 branch, 拼接 archive/{branch}.zip
- 定时检查: 每6h 拉取 version.json 比对版本
- 更新前自动打包备份 (zip, 保留最新5个)
- 保护用户配置: base_config.yaml / plugins/*/config.yaml / data/
- 子进程 pip install 依赖

API:
- GET /api/updates — 更新状态
- POST /api/updates/check — 手动检查
- POST /api/updates/apply — 执行更新

回滚:
- python main.py --rollback  — 恢复到最新备份
- 无备份时提示

重启:
- .restart_flag 信号文件 → 优雅退出 → systemd 拉起

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
qinglong
2026-06-13 20:32:42 +08:00
parent 6e0ed23012
commit c20417ff93
7 changed files with 401 additions and 2 deletions
+32
View File
@@ -40,6 +40,9 @@ def setup_routes(app, prefix=''):
app.router.add_get(f'{prefix}/api/framework', panel_auth(get_framework))
app.router.add_get(f'{prefix}/api/system', panel_auth(get_system))
app.router.add_get(f'{prefix}/api/system/ws', _ws_auth_wrapper(sys_ws_handler))
app.router.add_get(f'{prefix}/api/updates', panel_auth(get_updates))
app.router.add_post(f'{prefix}/api/updates/check', panel_auth(check_now))
app.router.add_post(f'{prefix}/api/updates/apply', panel_auth(apply_update))
logger.info(f"📡 系统状态WS端点已注册: {prefix}/api/system/ws (已加认证)")
def _read_version():
@@ -128,3 +131,32 @@ async def sys_ws_handler(req):
pass
_sys_ws_clients.discard(ws)
return ws
async def get_updates(req):
"""获取更新状态"""
sm = req.app.get("service_manager")
us = sm.get_service("update") if sm else None
if not us:
return web.json_response({"error": "更新服务未就绪"}, status=503)
return web.json_response(us.status)
async def check_now(req):
"""手动触发更新检查"""
sm = req.app.get("service_manager")
us = sm.get_service("update") if sm else None
if not us:
return web.json_response({"error": "更新服务未就绪"}, status=503)
await us.check_now()
return web.json_response(us.status)
async def apply_update(req):
"""执行更新"""
sm = req.app.get("service_manager")
us = sm.get_service("update") if sm else None
if not us:
return web.json_response({"error": "更新服务未就绪"}, status=503)
result = await us.apply_update()
return web.json_response(result)