Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
I
install.api
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Script
install.api
Commits
9cae8bcb
Commit
9cae8bcb
authored
Mar 20, 2020
by
金凯强
🎨
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
远程升级修改成异步处理
parent
e984593d
Pipeline
#21136
passed with stage
in 34 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
35 deletions
+47
-35
upgarde_api.py
app/upgrade/upgarde_api.py
+1
-1
upgrade_service.py
app/upgrade/upgrade_service.py
+46
-34
No files found.
app/upgrade/upgarde_api.py
View file @
9cae8bcb
...
@@ -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_upgrade
1
(
self
):
'''
'''
远程升级---1
远程升级---1
:return:
:return:
...
...
app/upgrade/upgrade_service.py
View file @
9cae8bcb
# -*- 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
):
'''
'''
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment