mirror of
https://github.com/Websoft9/websoft9.git
synced 2025-01-24 10:17:15 +08:00
appmanage:add some functions
This commit is contained in:
parent
431e14cdf0
commit
1959c785b1
@ -81,3 +81,72 @@ def install_app(app_name):
|
|||||||
ret["message"] = "应用正在启动中,请过几分钟再查询"
|
ret["message"] = "应用正在启动中,请过几分钟再查询"
|
||||||
ret["data"] = ""
|
ret["data"] = ""
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
def if_app_exits(app_name):
|
||||||
|
cmd = "docker compose ls -a | grep \'"+app_name+"\\b\'"
|
||||||
|
output = shell_execute.execute_command_output_all(cmd)
|
||||||
|
if int(output["code"]) == -1:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
def start_app(app_name):
|
||||||
|
ret = {}
|
||||||
|
ret["code"] = -1
|
||||||
|
if if_app_exits(app_name):
|
||||||
|
cmd = "docker start "+app_name
|
||||||
|
output = shell_execute.execute_command_output_all(cmd)
|
||||||
|
if int(output["code"]) == 0:
|
||||||
|
ret["code"] = 0
|
||||||
|
ret["message"] = "应用启动成功"
|
||||||
|
else:
|
||||||
|
ret["message"] = "应用启动失败"
|
||||||
|
else:
|
||||||
|
ret["message"] = "应用不存在"
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def stop_app(app_name):
|
||||||
|
ret = {}
|
||||||
|
ret["code"] = -1
|
||||||
|
if if_app_exits(app_name):
|
||||||
|
cmd = "docker stop " + app_name
|
||||||
|
output = shell_execute.execute_command_output_all(cmd)
|
||||||
|
if int(output["code"]) == 0:
|
||||||
|
ret["code"] = 0
|
||||||
|
ret["message"] = "应用停止成功"
|
||||||
|
else:
|
||||||
|
ret["message"] = "应用停止失败"
|
||||||
|
else:
|
||||||
|
ret["message"] = "应用不存在"
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def restart_app(app_name):
|
||||||
|
ret = {}
|
||||||
|
ret["code"] = -1
|
||||||
|
if if_app_exits(app_name):
|
||||||
|
cmd = "docker restart " + app_name
|
||||||
|
output = shell_execute.execute_command_output_all(cmd)
|
||||||
|
if int(output["code"]) == 0:
|
||||||
|
ret["code"] = 0
|
||||||
|
ret["message"] = "应用重启成功"
|
||||||
|
else:
|
||||||
|
ret["message"] = "应用重启失败"
|
||||||
|
else:
|
||||||
|
ret["message"] = "应用不存在"
|
||||||
|
return ret
|
||||||
|
|
||||||
|
def delete_app(app_name):
|
||||||
|
ret = {}
|
||||||
|
ret["code"] = -1
|
||||||
|
if_stopped = stop_app(app_name)
|
||||||
|
if if_stopped["code"] == 0:
|
||||||
|
cmd = "docker rm "+app_name
|
||||||
|
output = shell_execute.execute_command_output_all(cmd)
|
||||||
|
if int(output["code"]) == 0:
|
||||||
|
ret["code"] = 0
|
||||||
|
ret["message"] = "应用删除成功"
|
||||||
|
else:
|
||||||
|
ret["message"] = "应用删除失败"
|
||||||
|
else:
|
||||||
|
ret["message"] = if_stopped["message"]
|
||||||
|
return ret
|
||||||
|
@ -23,20 +23,20 @@ def install_app(app_name: Optional[str] = None):
|
|||||||
|
|
||||||
@router.get("/start")
|
@router.get("/start")
|
||||||
def start_app(app_name: Optional[str] = None):
|
def start_app(app_name: Optional[str] = None):
|
||||||
|
ret = manage.start_app(app_name)
|
||||||
return {}
|
return JSONResponse(content=ret)
|
||||||
|
|
||||||
@router.get("/stop")
|
@router.get("/stop")
|
||||||
def stop_app(app_name: Optional[str] = None):
|
def stop_app(app_name: Optional[str] = None):
|
||||||
|
ret = manage.stop_app(app_name)
|
||||||
return {}
|
return JSONResponse(content=ret)
|
||||||
|
|
||||||
@router.get("/restart")
|
@router.get("/restart")
|
||||||
def restart_app(app_name: Optional[str] = None):
|
def restart_app(app_name: Optional[str] = None):
|
||||||
|
ret = manage.restart(app_name)
|
||||||
return {}
|
return JSONResponse(content=ret)
|
||||||
|
|
||||||
@router.get("/delete")
|
@router.get("/delete")
|
||||||
def delete_app(app_name: Optional[str] = None):
|
def delete_app(app_name: Optional[str] = None):
|
||||||
|
ret = manage.delete_app(app_name)
|
||||||
return {}
|
return JSONResponse(content=ret)
|
||||||
|
Loading…
Reference in New Issue
Block a user