From f6f6f55e6ebc932f3d47ba76be00458e999ee240 Mon Sep 17 00:00:00 2001 From: midoks Date: Tue, 28 Jun 2022 20:05:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=88=A0=E9=99=A4=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- class/core/files_api.py | 42 +++++++++++++++++++++++----------------- class/core/system_api.py | 6 ++++++ 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/class/core/files_api.py b/class/core/files_api.py index d64dc8aca..8f7974d8f 100755 --- a/class/core/files_api.py +++ b/class/core/files_api.py @@ -191,34 +191,40 @@ class files_api: # self.setFileAccept(path + '/' + filename) return mw.returnJson(True, '已将下载任务添加到队列!') + # 删除进程下的所有进程 + def removeTaskRecursion(self, pid): + cmd = "ps -ef|grep " + pid + \ + " | grep -v grep |sed -n '2,1p' | awk '{print $2}'" + sub_pid = mw.execShell(cmd) + + if sub_pid[0].strip() == '': + return 'ok' + + self.removeTaskRecursion(sub_pid[0].strip()) + mw.execShell('kill -9 ' + sub_pid[0].strip()) + return sub_pid[0].strip() + def removeTaskApi(self): + import system_api mid = request.form.get('id', '') try: name = mw.M('tasks').where('id=?', (mid,)).getField('name') status = mw.M('tasks').where('id=?', (mid,)).getField('status') + # print(name, status) mw.M('tasks').delete(mid) if status == '-1': - os.system( - "kill `ps -ef |grep 'python panelSafe.pyc'|grep -v grep|grep -v panelExec|awk '{print $2}'`") - os.system( - "kill `ps aux | grep 'python task.pyc$'|awk '{print $2}'`") - os.system(''' -pids=`ps aux | grep 'sh'|grep -v grep|grep install|awk '{print $2}'` -arr=($pids) - -for p in ${arr[@]} -do - kill -9 $p -done - ''') - - os.system( - 'rm -f ' + name.replace('扫描目录[', '').replace(']', '') + '/scan.pl') + task_pid = mw.execShell( + "ps aux | grep 'task.py' | grep -v grep |awk '{print $2}'") + + task_list = task_pid[0].strip().split("\n") + for i in range(len(task_list)): + self.removeTaskRecursion(task_list[i]) + isTask = mw.getRootDir() + '/tmp/panelTask.pl' mw.writeFile(isTask, 'True') - os.system('/etc/init.d/mw start') + system_api.system_api().restartTask() except: - os.system('/etc/init.d/mw start') + system_api.system_api().restartTask() return mw.returnJson(True, '任务已删除!') # 上传文件 diff --git a/class/core/system_api.py b/class/core/system_api.py index 87fb6222f..f16705521 100755 --- a/class/core/system_api.py +++ b/class/core/system_api.py @@ -102,6 +102,12 @@ class system_api: return mw.returnJson(True, '正在重启服务器!') ##### ----- end ----- ### + def restartTask(self): + initd = mw.getRunDir() + '/scripts/init.d/mw' + if os.path.exists(initd): + os.system(initd + ' ' + 'restart_task') + return True + def restartMw(self): mw.writeFile('data/restart.pl', 'True') return True