Commit 9cae8bcb authored by 金凯强's avatar 金凯强 🎨

远程升级修改成异步处理

parent e984593d
Pipeline #21136 passed with stage
in 34 seconds
...@@ -33,7 +33,7 @@ class UpgradeAPI(ApiController): ...@@ -33,7 +33,7 @@ class UpgradeAPI(ApiController):
return UpgradeService().remote_upgrade(log_id) return UpgradeService().remote_upgrade(log_id)
@api('remote/step1') @api('remote/step1')
def get_remote_upgrade(self): def get_remote_upgrade1(self):
''' '''
远程升级---1 远程升级---1
:return: :return:
......
# -*- coding:utf-8 -*- # -*- coding:utf-8 -*-
import os import os
import re import re
from threading import Thread
from huansi_utils.app.apploader import logger from huansi_utils.app.apploader import logger
from huansi_utils.exception.exception import HSException from huansi_utils.exception.exception import HSException
...@@ -108,53 +109,64 @@ docker-compose -f /data/upgrade_tools_data/backup/{upgrade_no}/docker-compose.ym ...@@ -108,53 +109,64 @@ docker-compose -f /data/upgrade_tools_data/backup/{upgrade_no}/docker-compose.ym
raise HSException(f'未找到{docker_compose_file_dir}') raise HSException(f'未找到{docker_compose_file_dir}')
return docker_compose_file_dir return docker_compose_file_dir
def remote_upgrade(self, log_id=None): def _remote_upgrade(self, log_id):
''' from flask_app import global_app
远程升级 with global_app.app_context():
:return: from flask import g
''' g.user = {}
g.language = 'cn'
upgrade_no = self.get_upgrade_no_by_log_id(log_id)
upgrade_no = self.get_upgrade_no_by_log_id(log_id) self._package_images(upgrade_no)
self._package_images(upgrade_no) # 找到服务器ip
# 上传app包到服务器
remote_server_info = ConnectionService().get_remote_server_info()
if not remote_server_info:
raise HSException('远端服务器信息未查到,请先配置')
# 找到服务器ip ssh_conenct = SSHConnect(host_ip=remote_server_info['server_ip'],
# 上传app包到服务器 host_port=remote_server_info['server_ssh_port'],
remote_server_info = ConnectionService().get_remote_server_info() user_name=remote_server_info['server_user'],
if not remote_server_info: password=remote_server_info['server_password'])
raise HSException('远端服务器信息未查到,请先配置')
ssh_conenct = SSHConnect(host_ip=remote_server_info['server_ip'], # 复制文件到待上传的目录
host_port=remote_server_info['server_ssh_port'],
user_name=remote_server_info['server_user'],
password=remote_server_info['server_password'])
# 复制文件到待上传的目录 upgrade_back_up_dir = os.path.join(temp_file_dir, 'backup', upgrade_no)
upgrade_back_up_dir = os.path.join(temp_file_dir, 'backup', upgrade_no) with ssh_conenct as ssh:
with ssh_conenct as ssh: # 验证远端服务器有没有按照docker
self.validate_remote_server_install_docker(ssh)
# 验证远端服务器有没有按照docker for files in os.listdir(upgrade_back_up_dir):
self.validate_remote_server_install_docker(ssh) path = os.path.join(upgrade_back_up_dir, files)
# 隐藏文件不复制
if files.startswith('.'):
continue
logger.info(f"地址:{path}---->/huansi/upgrade/{files}")
ssh.upload(path, f'/huansi/upgrade/{files}')
for files in os.listdir(upgrade_back_up_dir): ssh.upload(os.path.join(system_file_dir, 'load.sh'), '/huansi/upgrade/load.sh')
path = os.path.join(upgrade_back_up_dir, files) ssh.upload(os.path.join(profile_dir, 'huansi.sh'), '/huansi/upgrade/huansi.sh')
# 隐藏文件不复制 ssh.upload(os.path.join(system_file_dir, 'load_handle.py'), '/huansi/upgrade/load_handle.py')
if files.startswith('.'):
continue
logger.info(f"地址:{path}---->/huansi/upgrade/{files}")
ssh.upload(path, f'/huansi/upgrade/{files}')
ssh.upload(os.path.join(system_file_dir, 'load.sh'), '/huansi/upgrade/load.sh') out, err = ssh.exec_command("sh /huansi/upgrade/load.sh")
ssh.upload(os.path.join(profile_dir, 'huansi.sh'), '/huansi/upgrade/huansi.sh')
ssh.upload(os.path.join(system_file_dir, 'load_handle.py'), '/huansi/upgrade/load_handle.py')
out, err = ssh.exec_command("sh /huansi/upgrade/load.sh") logger.info(f'远程升级信息:{out},远程错误信息:{out}')
logger.info(f'远程升级完成')
logger.info(f'远程升级信息:{out},远程错误信息:{out}') return {'message': '升级完成', out: err}
def remote_upgrade(self, log_id=None):
'''
远程升级
:return:
'''
t = Thread(target=self._remote_upgrade, args=(log_id,))
t.start()
return {'message': '升级完成', out: err} return {"message": "开始安装runner"}
def remote_upgrade_step1(self): def remote_upgrade_step1(self):
''' '''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment