fix 重启失败提示
This commit is contained in:
@ -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)
|
||||
|
@ -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)}"
|
||||
|
Reference in New Issue
Block a user