update manage.py

This commit is contained in:
TooY 2023-03-21 17:57:43 +08:00
parent e90940ae58
commit c182453240

View File

@ -185,34 +185,47 @@ def install_app_process(app_id):
ret = ret.dict()
return ret
def install_app(app_name, customer_app_name, app_version):
app_id = app_name + "_" + customer_app_name
library_path = "/data/library/"+app_name
install_path = "/data/apps/"+customer_app_name
ret = Response(code=const.RETURN_FAIL, message=" ")
def check_app(app_name, customer_app_name, app_version):
message = " "
install_path = "/data/apps/" + customer_app_name
if app_name==None or customer_app_name==None or app_version==None:
ret.message = "请将APP信息填写完整"
message = "请将APP信息填写完整"
elif not docker.check_app_directory(app_name):
ret.message = "不支持安装该APP"
message = "不支持安装该APP"
elif re.match('^[a-z0-9]+$', customer_app_name)==None:
ret.message = "应用名称必须为小写字母和数字"
message = "应用名称必须为小写字母和数字"
elif docker.check_app_directory(install_path):
ret.message = "APP名称已经使用请指定其他名称重新安装。"
message = "APP名称已经使用请指定其他名称重新安装。"
elif not docker.check_vm_resource(app_name):
ret.message = "系统资源(内存、CPU、磁盘)不足,继续安装可能导致应用无法运行或服务器异常!"
else:
output = shell_execute.execute_command_output_all("cp -r " + library_path + " " + install_path)
if int(output["code"]) != 0:
ret.message = "创建" + customer_app_name + "目录失败"
else:
message = "系统资源(内存、CPU、磁盘)不足,继续安装可能导致应用无法运行或服务器异常!"
return message
def prepare_app(app_name, customer_app_name):
library_path = "/data/library/" + app_name
install_path = "/data/apps/" + customer_app_name
message = " "
output = shell_execute.execute_command_output_all("cp -r " + library_path + " " + install_path)
if int(output["code"]) != 0:
message = "创建" + customer_app_name + "目录失败"
return message
def install_app(app_name, customer_app_name, app_version):
ret = Response(code=const.RETURN_FAIL, message=" ")
ret.message = check_app(app_name, customer_app_name, app_version)
if ret.message != " ":
ret.message = prepare_app(app_name, customer_app_name)
if ret.message != " ":
t1 = Thread(target=record_and_install_app, args=(customer_app_name, app_version,))
t1.start()
ret.code = const.RETURN_SUCCESS
ret.message="应用正在启动中,请过几分钟再查询"
ret = ret.dict()
return ret
def record_and_install_app(customer_app_name, app_version):
def install_app_job(customer_app_name, app_version):
file_path = "/data/apps/running_apps.txt"
with open(file_path, "a", encoding="utf-8") as f:
f.write(customer_app_name + "\n")
@ -235,7 +248,6 @@ def record_and_install_app(customer_app_name, app_version):
f.write(file_data)
def if_app_exits(app_id, app_name):
cmd = "docker compose ls -a | grep \'"+app_name+"\\b\'"
output = shell_execute.execute_command_output_all(cmd)