mirror of https://github.com/midoks/mdserver-web
parent
ed90f9a087
commit
3ce1289c44
@ -0,0 +1,54 @@ |
|||||||
|
# coding:utf-8 |
||||||
|
|
||||||
|
# --------------------------------------------------------------------------------- |
||||||
|
# MW-Linux面板 |
||||||
|
# --------------------------------------------------------------------------------- |
||||||
|
# copyright (c) 2018-∞(https://github.com/midoks/mdserver-web) All rights reserved. |
||||||
|
# --------------------------------------------------------------------------------- |
||||||
|
# Author: midoks <midoks@163.com> |
||||||
|
# --------------------------------------------------------------------------------- |
||||||
|
|
||||||
|
import os |
||||||
|
import shutil |
||||||
|
|
||||||
|
import core.mw as mw |
||||||
|
|
||||||
|
def contentReplace(src, dst): |
||||||
|
content = mw.readFile(src) |
||||||
|
content = content.replace("{$SERVER_PATH}", mw.getFatherDir()) |
||||||
|
|
||||||
|
content += "\n# make:{0}".format(mw.formatDate()) |
||||||
|
mw.writeFile(dst, content) |
||||||
|
|
||||||
|
|
||||||
|
def init_cmd(): |
||||||
|
script = mw.getPanelDir() + '/scripts/init.d/mw.tpl' |
||||||
|
script_bin = mw.getPanelDir() + '/scripts/init.d/mw' |
||||||
|
contentReplace(script, script_bin) |
||||||
|
mw.execShell('chmod +x ' + script_bin) |
||||||
|
|
||||||
|
# 在linux系统中,确保/etc/init.d存在 |
||||||
|
if not mw.isAppleSystem() and not os.path.exists("/etc/rc.d/init.d"): |
||||||
|
mw.execShell('mkdir -p /etc/rc.d/init.d') |
||||||
|
|
||||||
|
if not mw.isAppleSystem() and not os.path.exists("/etc/init.d"): |
||||||
|
mw.execShell('mkdir -p /etc/init.d') |
||||||
|
|
||||||
|
# initd |
||||||
|
if os.path.exists('/etc/rc.d/init.d'): |
||||||
|
initd_bin = '/etc/rc.d/init.d/mw' |
||||||
|
if not os.path.exists(initd_bin): |
||||||
|
shutil.copyfile(script_bin, initd_bin) |
||||||
|
mw.execShell('chmod +x ' + initd_bin) |
||||||
|
# 加入自启动 |
||||||
|
mw.execShell('which chkconfig && chkconfig --add mw') |
||||||
|
|
||||||
|
if os.path.exists('/etc/init.d'): |
||||||
|
initd_bin = '/etc/init.d/mw' |
||||||
|
if not os.path.exists(initd_bin): |
||||||
|
import shutil |
||||||
|
shutil.copyfile(script_bin, initd_bin) |
||||||
|
mw.execShell('chmod +x ' + initd_bin) |
||||||
|
# 加入自启动 |
||||||
|
mw.execShell('which update-rc.d && update-rc.d -f mw defaults') |
||||||
|
return True |
@ -0,0 +1,11 @@ |
|||||||
|
# coding:utf-8 |
||||||
|
|
||||||
|
# --------------------------------------------------------------------------------- |
||||||
|
# MW-Linux面板 |
||||||
|
# --------------------------------------------------------------------------------- |
||||||
|
# copyright (c) 2018-∞(https://github.com/midoks/mdserver-web) All rights reserved. |
||||||
|
# --------------------------------------------------------------------------------- |
||||||
|
# Author: midoks <midoks@163.com> |
||||||
|
# --------------------------------------------------------------------------------- |
||||||
|
|
||||||
|
from .option import * |
@ -0,0 +1,28 @@ |
|||||||
|
# coding:utf-8 |
||||||
|
|
||||||
|
# --------------------------------------------------------------------------------- |
||||||
|
# MW-Linux面板 |
||||||
|
# --------------------------------------------------------------------------------- |
||||||
|
# copyright (c) 2018-∞(https://github.com/midoks/mdserver-web) All rights reserved. |
||||||
|
# --------------------------------------------------------------------------------- |
||||||
|
# Author: midoks <midoks@163.com> |
||||||
|
# --------------------------------------------------------------------------------- |
||||||
|
|
||||||
|
|
||||||
|
import core.mw as mw |
||||||
|
|
||||||
|
def getOption(name, |
||||||
|
type: str | None = 'common', |
||||||
|
default : str | None = None |
||||||
|
) -> str: |
||||||
|
''' |
||||||
|
获取配置的值 |
||||||
|
:name -> str 名称 (必填) |
||||||
|
:type -> str 类型 (可选|默认common) |
||||||
|
:default -> str 默认值 (可选) |
||||||
|
''' |
||||||
|
data = mw.M('option').field('name').where('name=? and type=?',(name, type,)).getField('value') |
||||||
|
|
||||||
|
if len(data) == 0: |
||||||
|
return default |
||||||
|
return data |
@ -0,0 +1,54 @@ |
|||||||
|
# coding:utf-8 |
||||||
|
|
||||||
|
# --------------------------------------------------------------------------------- |
||||||
|
# MW-Linux面板 |
||||||
|
# --------------------------------------------------------------------------------- |
||||||
|
# copyright (c) 2018-∞(https://github.com/midoks/mdserver-web) All rights reserved. |
||||||
|
# --------------------------------------------------------------------------------- |
||||||
|
# Author: midoks <midoks@163.com> |
||||||
|
# --------------------------------------------------------------------------------- |
||||||
|
|
||||||
|
import os |
||||||
|
import pwd |
||||||
|
import time |
||||||
|
|
||||||
|
import core.mw as mw |
||||||
|
|
||||||
|
# 删除进程下的所有进程 |
||||||
|
def removeTaskRecursion(pid): |
||||||
|
cmd = "ps -ef|grep %s | grep -v grep |sed -n '2,1p' | awk '{print $2}'" % pid |
||||||
|
sub_pid = mw.execShell(cmd) |
||||||
|
if sub_pid[0].strip() == '': |
||||||
|
return 'ok' |
||||||
|
|
||||||
|
if sub_pid[0].strip() == pid : |
||||||
|
return 'ok' |
||||||
|
|
||||||
|
removeTaskRecursion(sub_pid[0].strip()) |
||||||
|
mw.execShell('kill -9 ' + sub_pid[0].strip()) |
||||||
|
return sub_pid[0].strip() |
||||||
|
|
||||||
|
# 删除任务 |
||||||
|
def removeTask(task_id): |
||||||
|
try: |
||||||
|
name = mw.M('tasks').where('id=?', (task_id,)).getField('name') |
||||||
|
status = mw.M('tasks').where('id=?', (task_id,)).getField('status') |
||||||
|
mw.M('tasks').delete(task_id) |
||||||
|
if str(status) == '-1': |
||||||
|
cmd = "ps aux | grep 'panel_task.py' | grep -v grep |awk '{print $2}'" |
||||||
|
task_pid = mw.execShell(cmd) |
||||||
|
task_list = task_pid[0].strip().split("\n") |
||||||
|
for i in range(len(task_list)): |
||||||
|
removeTaskRecursion(task_list[i]) |
||||||
|
t = mw.execShell('kill -9 ' + task_list[i]) |
||||||
|
print(t) |
||||||
|
mw.triggerTask() |
||||||
|
mw.restartTask() |
||||||
|
except Exception as e: |
||||||
|
mw.restartTask() |
||||||
|
|
||||||
|
# 删除日志 |
||||||
|
task_log = mw.getPanelDir() + "/tmp/panelTask.pl" |
||||||
|
if os.path.exists(task_log): |
||||||
|
os.remove(task_log) |
||||||
|
return mw.returnData(True, '任务已删除!') |
Loading…
Reference in new issue