diff --git a/plugins/migration_api/index.py b/plugins/migration_api/index.py
index 7851879ae..f69f6cbf8 100755
--- a/plugins/migration_api/index.py
+++ b/plugins/migration_api/index.py
@@ -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, '创建进程失败!
{}'.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')
diff --git a/plugins/migration_api/js/app.js b/plugins/migration_api/js/app.js
index 9bbc0c2bf..a971f0bfa 100755
--- a/plugins/migration_api/js/app.js
+++ b/plugins/migration_api/js/app.js
@@ -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 = '
传输大小: 4.92 KB,耗时: 0分6秒,平均速度: 840 B/s
\ + //\ + // \ + // 迁移日志\ + //
\ + //