feat(server): 添加系统重启功能支持
添加后台任务支持用于处理系统重启请求,实现延迟进程终止机制, 允许系统安全地重启并在重启后自动恢复服务。 feat(frontend): 实现前端系统重启控制面板 在状态页面添加重启对话框组件,提供用户友好的重启确认界面, 包含重启状态监控和错误处理功能,确保用户可以安全重启系统。 docs(deployment): 更新部署指南添加URL协议要求说明 详细说明NANO_AUTHZ_URL和NANO_DEPLOY_URL环境变量必须包含 http://协议前缀的要求,添加常见错误示例和容器重建步骤, 帮助用户避免注册页面502错误问题。
This commit is contained in:
@ -18,6 +18,7 @@ from urllib.parse import urlsplit, urlunsplit
|
||||
|
||||
import httpx
|
||||
from fastapi import (
|
||||
BackgroundTasks,
|
||||
FastAPI,
|
||||
File,
|
||||
Form,
|
||||
@ -112,6 +113,13 @@ async def _reconcile_managed_outlook_mcp(config: Config) -> bool:
|
||||
return before != after
|
||||
|
||||
|
||||
def _terminate_process_after_delay(delay_seconds: float = 1.0, exit_code: int = 1) -> None:
|
||||
if delay_seconds > 0:
|
||||
time.sleep(delay_seconds)
|
||||
logger.warning("Self-restart requested; exiting backend process with code {}", exit_code)
|
||||
os._exit(exit_code)
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# Request/Response models
|
||||
# ============================================================================
|
||||
@ -1534,6 +1542,20 @@ def _register_routes(app: FastAPI) -> None:
|
||||
app.state.auth_tokens.pop(token, None)
|
||||
return {"ok": True}
|
||||
|
||||
@app.post("/api/system/restart", status_code=202)
|
||||
async def restart_system(
|
||||
background_tasks: BackgroundTasks,
|
||||
authorization: str | None = Header(default=None),
|
||||
):
|
||||
username = _require_web_user(app, authorization)
|
||||
logger.warning("Restart requested by user {}", username)
|
||||
background_tasks.add_task(_terminate_process_after_delay, 1.0, 1)
|
||||
return {
|
||||
"ok": True,
|
||||
"restarting": True,
|
||||
"detail": "Restart scheduled",
|
||||
}
|
||||
|
||||
# ------ Chat ------
|
||||
|
||||
@app.post("/api/chat")
|
||||
|
||||
Reference in New Issue
Block a user