fix api
This commit is contained in:
@ -300,20 +300,21 @@ class SystemUtils:
|
||||
"""
|
||||
判断是否可以内部重启
|
||||
"""
|
||||
if not SystemUtils.is_docker():
|
||||
return False
|
||||
return Path("/var/run/docker.sock").exists()
|
||||
|
||||
@staticmethod
|
||||
def restart_docker():
|
||||
def restart():
|
||||
"""
|
||||
执行Docker重启操作
|
||||
"""
|
||||
# 创建 Docker 客户端
|
||||
client = docker.from_env()
|
||||
# 获取当前容器的 ID
|
||||
container_id = open("/proc/self/cgroup", "r").read().split("/")[-1]
|
||||
if not container_id:
|
||||
return
|
||||
# 重启当前容器
|
||||
client.containers.get(container_id.strip()).restart()
|
||||
try:
|
||||
# 创建 Docker 客户端
|
||||
client = docker.from_env()
|
||||
# 获取当前容器的 ID
|
||||
container_id = open("/proc/self/cgroup", "r").read().split("/")[-1]
|
||||
if not container_id:
|
||||
return
|
||||
# 重启当前容器
|
||||
client.containers.get(container_id.strip()).restart()
|
||||
except Exception as err:
|
||||
print(str(err))
|
||||
|
Reference in New Issue
Block a user