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