mirror of
https://github.com/Websoft9/websoft9.git
synced 2025-01-25 02:38:42 +08:00
update
This commit is contained in:
parent
85d3ca23a1
commit
21b3995690
@ -39,29 +39,32 @@ def get_app_detail(app_id):
|
|||||||
ret['message'] = 'App query failed!'
|
ret['message'] = 'App query failed!'
|
||||||
ret['data'] = None
|
ret['data'] = None
|
||||||
|
|
||||||
# get all info
|
if docker.check_app_id(app_id):
|
||||||
cmd = "docker compose ls -a --format json"
|
# get all info
|
||||||
output = shell_execute.execute_command_output_all(cmd)
|
cmd = "docker compose ls -a --format json"
|
||||||
if int(output["code"]) == 0:
|
output = shell_execute.execute_command_output_all(cmd)
|
||||||
output_list = json.loads(output["result"])
|
if int(output["code"]) == 0:
|
||||||
app_list, has_add = get_apps_from_compose(output_list)
|
output_list = json.loads(output["result"])
|
||||||
list = get_apps_from_queue(app_list, has_add)
|
app_list, has_add = get_apps_from_compose(output_list)
|
||||||
flag = 0
|
list = get_apps_from_queue(app_list, has_add)
|
||||||
app_info = None
|
flag = 0
|
||||||
for app in list:
|
app_info = None
|
||||||
if app["app_id"] == app_id:
|
for app in list:
|
||||||
list.clear()
|
if app["app_id"] == app_id:
|
||||||
list.append(app)
|
list.clear()
|
||||||
app_info = App(app_id=app['app_id'], name=app['name'], customer_name=app['customer_name'], status_code=app['status_code'], status=app['status'], port=app['port'],
|
list.append(app)
|
||||||
volume=app['volume'], url=app['url'],
|
app_info = App(app_id=app['app_id'], name=app['name'], customer_name=app['customer_name'], status_code=app['status_code'], status=app['status'], port=app['port'],
|
||||||
image_url=app['image_url'], admin_url=app['admin_url'], trade_mark=app['trade_mark'], user_name=app['user_name'],
|
volume=app['volume'], url=app['url'],
|
||||||
password=app['password'])
|
image_url=app['image_url'], admin_url=app['admin_url'], trade_mark=app['trade_mark'], user_name=app['user_name'],
|
||||||
flag = 1
|
password=app['password'])
|
||||||
break
|
flag = 1
|
||||||
if flag == 1:
|
break
|
||||||
ret['code'] = const.RETURN_SUCCESS
|
if flag == 1:
|
||||||
ret['message'] = "The app query is successful."
|
ret['code'] = const.RETURN_SUCCESS
|
||||||
ret['data'] = app_info
|
ret['message'] = "The app query is successful."
|
||||||
|
ret['data'] = app_info
|
||||||
|
else:
|
||||||
|
ret['message'] = "AppID is not legal!"
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
@ -95,73 +98,85 @@ def install_app(app_name, customer_app_name, app_version):
|
|||||||
|
|
||||||
def start_app(app_id):
|
def start_app(app_id):
|
||||||
ret = Response(code=const.RETURN_FAIL, message="")
|
ret = Response(code=const.RETURN_FAIL, message="")
|
||||||
app_name = split_app_id(app_id)
|
if docker.check_app_id(app_id):
|
||||||
if if_app_exits(app_id, app_name):
|
app_name = split_app_id(app_id)
|
||||||
docker.check_app_compose(app_name)
|
if if_app_exits(app_id, app_name):
|
||||||
cmd = "docker compose -f /data/apps/" + app_name + "/docker-compose.yml start"
|
docker.check_app_compose(app_name)
|
||||||
output = shell_execute.execute_command_output_all(cmd)
|
cmd = "docker compose -f /data/apps/" + app_name + "/docker-compose.yml start"
|
||||||
if int(output["code"]) == 0:
|
output = shell_execute.execute_command_output_all(cmd)
|
||||||
ret.code = const.RETURN_SUCCESS
|
if int(output["code"]) == 0:
|
||||||
ret.message = "The app starts successfully."
|
ret.code = const.RETURN_SUCCESS
|
||||||
|
ret.message = "The app starts successfully."
|
||||||
|
else:
|
||||||
|
ret.message = "The app failed to start!"
|
||||||
else:
|
else:
|
||||||
ret.message = "The app failed to start!"
|
ret.message = "The app is not installed!"
|
||||||
else:
|
else:
|
||||||
ret.message = "The app is not installed!"
|
ret.message = "AppID is not legal!"
|
||||||
ret = ret.dict()
|
ret = ret.dict()
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def stop_app(app_id):
|
def stop_app(app_id):
|
||||||
ret = Response(code=const.RETURN_FAIL, message="")
|
ret = Response(code=const.RETURN_FAIL, message="")
|
||||||
app_name = split_app_id(app_id)
|
if docker.check_app_id(app_id):
|
||||||
if if_app_exits(app_id, app_name):
|
app_name = split_app_id(app_id)
|
||||||
cmd = "docker compose -f /data/apps/" + app_name + "/docker-compose.yml stop"
|
if if_app_exits(app_id, app_name):
|
||||||
output = shell_execute.execute_command_output_all(cmd)
|
cmd = "docker compose -f /data/apps/" + app_name + "/docker-compose.yml stop"
|
||||||
if int(output["code"]) == 0:
|
output = shell_execute.execute_command_output_all(cmd)
|
||||||
ret.code = const.RETURN_SUCCESS
|
if int(output["code"]) == 0:
|
||||||
ret.message = "The app stopped successfully."
|
ret.code = const.RETURN_SUCCESS
|
||||||
|
ret.message = "The app stopped successfully."
|
||||||
|
else:
|
||||||
|
ret.message = "App stop failed!"
|
||||||
else:
|
else:
|
||||||
ret.message = "App stop failed!"
|
ret.message = "The app is not installed!"
|
||||||
else:
|
else:
|
||||||
ret.message = "The app is not installed!"
|
ret.message = 'AppID is not legal!'
|
||||||
ret = ret.dict()
|
ret = ret.dict()
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def restart_app(app_id):
|
def restart_app(app_id):
|
||||||
ret = Response(code=const.RETURN_FAIL, message="")
|
ret = Response(code=const.RETURN_FAIL, message="")
|
||||||
app_name = split_app_id(app_id)
|
if docker.check_app_id(app_id):
|
||||||
if if_app_exits(app_id, app_name):
|
app_name = split_app_id(app_id)
|
||||||
cmd = "docker compose -f /data/apps/" + app_name + "/docker-compose.yml restart"
|
if if_app_exits(app_id, app_name):
|
||||||
output = shell_execute.execute_command_output_all(cmd)
|
cmd = "docker compose -f /data/apps/" + app_name + "/docker-compose.yml restart"
|
||||||
if int(output["code"]) == 0:
|
output = shell_execute.execute_command_output_all(cmd)
|
||||||
ret.code = const.RETURN_SUCCESS
|
if int(output["code"]) == 0:
|
||||||
ret.message = "The app restarts successfully."
|
ret.code = const.RETURN_SUCCESS
|
||||||
|
ret.message = "The app restarts successfully."
|
||||||
|
else:
|
||||||
|
ret.message = "App restart failed!"
|
||||||
else:
|
else:
|
||||||
ret.message = "App restart failed!"
|
ret.message = "The app is not installed!"
|
||||||
else:
|
else:
|
||||||
ret.message = "The app is not installed!"
|
ret.message = 'AppID is not legal!'
|
||||||
ret = ret.dict()
|
ret = ret.dict()
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def uninstall_app(app_id):
|
def uninstall_app(app_id):
|
||||||
ret = Response(code=const.RETURN_FAIL, message="")
|
ret = Response(code=const.RETURN_FAIL, message="")
|
||||||
if_stopped = stop_app(app_id) # stop_app
|
if docker.check_app_id(app_id):
|
||||||
app_name = split_app_id(app_id)
|
if_stopped = stop_app(app_id) # stop_app
|
||||||
real_name = app_id.split("_")[0]
|
app_name = split_app_id(app_id)
|
||||||
if if_stopped["code"] == 0:
|
real_name = app_id.split("_")[0]
|
||||||
cmd = "docker compose -f /data/apps/" + app_name + "/docker-compose.yml down -v"
|
if if_stopped["code"] == 0:
|
||||||
if real_name != app_name:
|
cmd = "docker compose -f /data/apps/" + app_name + "/docker-compose.yml down -v"
|
||||||
cmd = cmd + " && sudo rm -rf /data/apps/" + app_name
|
if real_name != app_name:
|
||||||
output = shell_execute.execute_command_output_all(cmd)
|
cmd = cmd + " && sudo rm -rf /data/apps/" + app_name
|
||||||
if int(output["code"]) == 0:
|
output = shell_execute.execute_command_output_all(cmd)
|
||||||
ret.code = 0
|
if int(output["code"]) == 0:
|
||||||
ret.message = "The app is deleted successfully"
|
ret.code = 0
|
||||||
|
ret.message = "The app is deleted successfully"
|
||||||
|
else:
|
||||||
|
ret.message = "App deletion failed!"
|
||||||
else:
|
else:
|
||||||
ret.message = "App deletion failed!"
|
ret.message = if_stopped["message"]
|
||||||
else:
|
else:
|
||||||
ret.message = if_stopped["message"]
|
ret.message = 'AppID is not legal!'
|
||||||
ret = ret.dict()
|
ret = ret.dict()
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
@ -38,6 +38,25 @@ def if_app_exits(app_name):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def check_app_id(app_id):
|
||||||
|
myLogger.info_logger("Checking app id ...")
|
||||||
|
if app_id == None:
|
||||||
|
myLogger.info_logger("Check complete: AppID is none!")
|
||||||
|
return False
|
||||||
|
if re.match('^[a-zA-Z0-9]+_[a-z0-9]+$', app_id) == None:
|
||||||
|
myLogger.info_logger("Check complete: AppID is not compliant")
|
||||||
|
return False
|
||||||
|
app_name = app_id.split('_')[0]
|
||||||
|
customer_name = app_id.split('_')[1]
|
||||||
|
path1 = '/data/apps/' + customer_name
|
||||||
|
path2 = '/data/library/apps/' + app_name
|
||||||
|
if not check_directory(path1) or not check_directory(path2):
|
||||||
|
myLogger.info_logger("Check complete: AppID does not exist!")
|
||||||
|
return False
|
||||||
|
myLogger.info_logger("Check complete.")
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def check_vm_resource(app_name):
|
def check_vm_resource(app_name):
|
||||||
myLogger.info_logger("Checking virtual memory resource ...")
|
myLogger.info_logger("Checking virtual memory resource ...")
|
||||||
var_path = "/data/library/apps/" + app_name + "/variables.json"
|
var_path = "/data/library/apps/" + app_name + "/variables.json"
|
||||||
|
Loading…
Reference in New Issue
Block a user