diff --git a/app/api/endpoints/system.py b/app/api/endpoints/system.py index 7eca7a2d..e401c207 100644 --- a/app/api/endpoints/system.py +++ b/app/api/endpoints/system.py @@ -209,5 +209,5 @@ def restart_system(_: schemas.TokenPayload = Depends(verify_token)): if not SystemUtils.can_restart(): return schemas.Response(success=False, message="当前运行环境不支持重启操作!") # 执行重启 - SystemUtils.restart() - return schemas.Response(success=True) + ret, msg = SystemUtils.restart() + return schemas.Response(success=ret, message=msg) diff --git a/app/utils/system.py b/app/utils/system.py index a83d37af..72c96a39 100644 --- a/app/utils/system.py +++ b/app/utils/system.py @@ -303,7 +303,7 @@ class SystemUtils: return Path("/var/run/docker.sock").exists() @staticmethod - def restart(): + def restart() -> Tuple[bool, str]: """ 执行Docker重启操作 """ @@ -313,8 +313,10 @@ class SystemUtils: # 获取当前容器的 ID container_id = open("/proc/self/cgroup", "r").read().split("/")[-1] if not container_id: - return + return False, "获取容器ID失败!" # 重启当前容器 client.containers.get(container_id.strip()).restart() + return True, "" except Exception as err: print(str(err)) + return False, f"重启时发生错误:{str(err)}"