pull/382/head
midoks 2 years ago
parent 45a3eec1b5
commit c1f402b278
  1. 79
      plugins/migration_api/index.py
  2. 39
      plugins/migration_api/js/app.js
  3. 2
      scripts/install_dev.sh

@ -257,6 +257,52 @@ def stepThree():
return mw.returnJson(True, 'ok', data)
def getPid():
result = mw.execShell(
"ps aux|grep index.py|grep -v grep|awk '{print $2}'|xargs")[0].strip()
if not result:
import psutil
for pid in psutil.pids():
if not os.path.exists('/proc/{}'.format(pid)):
continue # 检查pid是否还存在
try:
p = psutil.Process(pid)
except:
return None
cmd = p.cmdline()
if len(cmd) < 2:
continue
if cmd[1].find('psync_api_main.py') != -1:
return pid
return None
def bgProcessRun():
time.sleep(10)
return '123123'
def bgProcess():
log_file = getServerDir() + '/sync.log'
log_file_error = getServerDir() + '/sync_error.log'
if os.path.exists(log_file_error):
os.remove(log_file_error)
if os.path.exists(log_file):
os.remove(log_file)
plugins_dir = mw.getServerDir() + '/mdserver-web'
exe = "cd {0} && source bin/activate && nohup python3 plugins/migration_api/index.py bg_process &>{1} &".format(
plugins_dir, log_file_error)
os.system(exe)
time.sleep(1)
# 检查是否执行成功
if not getPid():
return mw.returnJson(False, '创建进程失败!<br>{}'.format(mw.readFile(log_file_error)))
return mw.returnJson(True, "迁移进程创建成功!")
def stepFour():
args = getArgs()
data = checkArgs(args, ['sites', 'databases'])
@ -273,7 +319,36 @@ def stepFour():
}
data['ready'] = ready_data
writeConf(data)
return mw.returnJson(True, 'ok')
return bgProcess()
# return mw.returnJson(True, 'ok')
def get_speed_data():
path = getServerDir() + '/config/speed.json'
data = mw.readFile(path)
return json.loads(data)
def get_speed(args):
# 取迁移进度
if not os.path.exists(self._SPEED_FILE):
return public.returnMsg(False, '正在准备..')
try:
speed_info = json.loads(mw.readFile(self._SPEED_FILE))
except:
return False
sync_info = self.get_sync_info(None)
speed_info['all_total'] = sync_info['total']
speed_info['all_speed'] = sync_info['speed']
speed_info['total_time'] = speed_info['end_time'] - speed_info['time']
speed_info['total_time'] = str(int(speed_info[
'total_time'] // 60)) + "" + str(int(speed_info['total_time'] % 60)) + ""
log_file = '/www/server/panel/logs/psync.log'
speed_info['log'] = public.ExecShell(
"tail -n 10 {}".format(log_file))[0]
# if len(speed_info['log']) > 20480 and speed_info['action'] != 'True':
# return False
return speed_info
if __name__ == "__main__":
func = sys.argv[1]
@ -293,5 +368,7 @@ if __name__ == "__main__":
print(stepThree())
elif func == 'step_four':
print(stepFour())
elif func == 'bg_process':
print(bgProcessRun())
else:
print('error')

@ -76,7 +76,6 @@ function initStep1(){
var rdata = $.parseJSON(rdata.data);
showMsg(rdata.msg,function(){
if (rdata.status){
selectProgress(2);
initStep2();
}
},{ icon: rdata.status ? 1 : 2 });
@ -86,9 +85,9 @@ function initStep1(){
function initStep2(){
maPost('step_two',{}, function(rdata){
var rdata = $.parseJSON(rdata.data);
console.log(rdata);
showMsg(rdata.msg,function(){
if (rdata.status){
selectProgress(2);
$('.psync_info').hide();
var info = rdata.data;
@ -143,7 +142,6 @@ function initStep2(){
function initStep3(){
maPost('step_three',{}, function(rdata){
var rdata = $.parseJSON(rdata.data);
console.log(rdata);
showMsg(rdata.msg,function(){
if (rdata.status){
var pdata = rdata.data;
@ -189,6 +187,9 @@ function initStep3(){
});
}
function renderMer
function initStep4(){
var site_checked = '';
@ -204,20 +205,32 @@ function initStep4(){
maPost('step_four',{sites:site_checked,databases:databases_checked}, function(rdata){
var rdata = $.parseJSON(rdata.data);
var tby = '<div class="line">\
<div class="success text-center" style="padding: 10px 0 15px;">\
<p style="font-size: 14px;margin-top:2px;color: #939292;">传输大小: 4.92 KB,耗时: 0分6秒,平均速度: 840 B/s</p>\
<p class="mtb15">\
<button class="btn btn-success btn-sm mr5 okBtn">确定完成</button>\
<button class="btn btn-default btn-sm lookInfo">查看记录</button>\
<a class="btn btn-default btn-sm" style="margin-left: 10px;" href="/download?filename=/www/server/panel/logs/psync.log">迁移日志</a>\
</p>\
var progress = '<div style="margin: 0 40px;">\
<div class="line">\
<div style="text-align:left"><span>|-迁移网站: [dev156.cachecha.com]</span>\
<span style="margin-left: 20px;">当前: 正在压缩</span><img src="/static/img/ing.gif"><a style="position: absolute;right: 40px;" class="btlink psync_close" onclick="migrate.close();">[]</a></div>\
<div class="bt-progress" style="border-radius:0;height:20px;line-height:19px">\
<div class="bt-progress-bar" style="border-radius: 0px; height: 20px; width: 16.67%;">\
<span class="bt-progress-text">16.67%</span></div>\
</div>\
</div>\
</div>\
<pre style="height: 222px;text-align: left;margin:5px 38px 0;font-size: 12px;line-height: 20px;padding: 10px;background-color: #333;color: #fff;"></pre>\
</div>';
$('.psync_data').hide();
$('.psync_migrate').html(tby);
// var end = '<div class="line">\
// <div class="success text-center" style="padding: 10px 0 15px;">\
// <p style="font-size: 14px;margin-top:2px;color: #939292;">传输大小: 4.92 KB,耗时: 0分6秒,平均速度: 840 B/s</p>\
// <p class="mtb15">\
// <button class="btn btn-success btn-sm mr5 okBtn">确定完成</button>\
// <a class="btn btn-default btn-sm" style="margin-left: 10px;" href="/download?filename=/www/server/migration_api/logs/psync.log">迁移日志</a>\
// </p>\
// </div>\
// </div>';
$('.psync_data').hide();
$('.psync_migrate').html(progress);
$('.psync_migrate').show();
});
}

@ -61,8 +61,10 @@ fi
HTTP_PREFIX="https://"
LOCAL_ADDR=common
ping -c 1 github.com > /dev/null 2>&1
if [ "$?" != "0" ];then
LOCAL_ADDR=cn
HTTP_PREFIX="https://ghproxy.com/"
fi

Loading…
Cancel
Save