mirror of https://github.com/midoks/mdserver-web
parent
ae9e56c56c
commit
d6ccd81def
After Width: | Height: | Size: 3.1 KiB |
@ -0,0 +1,19 @@ |
|||||||
|
<div class="bt-form"> |
||||||
|
<div class='plugin_version'></div> |
||||||
|
<div class="bt-w-main"> |
||||||
|
<div class="bt-w-menu"> |
||||||
|
<p class="bgw" onclick="pluginService('dynamic-tracking');">服务</p> |
||||||
|
<p onclick="pluginInitD('dynamic-tracking');">自启动</p> |
||||||
|
<p onclick="pluginLogs('dynamic-tracking','','run_log');">日志</p> |
||||||
|
</div> |
||||||
|
<div class="bt-w-con pd15"> |
||||||
|
<div class="soft-man-con"></div> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
</div> |
||||||
|
<script type="text/javascript"> |
||||||
|
resetPluginWinHeight(300); |
||||||
|
$.getScript( "/plugins/file?name=dynamic-tracking&f=js/dynamic-tracking.js", function(){ |
||||||
|
pluginService('dynamic-tracking', $('.plugin_version').attr('version')); |
||||||
|
}); |
||||||
|
</script> |
@ -0,0 +1,206 @@ |
|||||||
|
# coding:utf-8 |
||||||
|
|
||||||
|
import sys |
||||||
|
import io |
||||||
|
import os |
||||||
|
import time |
||||||
|
import re |
||||||
|
|
||||||
|
sys.path.append(os.getcwd() + "/class/core") |
||||||
|
import mw |
||||||
|
|
||||||
|
app_debug = False |
||||||
|
if mw.isAppleSystem(): |
||||||
|
app_debug = True |
||||||
|
|
||||||
|
|
||||||
|
def getPluginName(): |
||||||
|
return 'dynamic-tracking' |
||||||
|
|
||||||
|
|
||||||
|
def getPluginDir(): |
||||||
|
return mw.getPluginDir() + '/' + getPluginName() |
||||||
|
|
||||||
|
|
||||||
|
def getServerDir(): |
||||||
|
return mw.getServerDir() + '/' + getPluginName() |
||||||
|
|
||||||
|
|
||||||
|
def getInitDFile(): |
||||||
|
if app_debug: |
||||||
|
return '/tmp/' + getPluginName() |
||||||
|
return '/etc/init.d/' + getPluginName() |
||||||
|
|
||||||
|
|
||||||
|
def getConf(): |
||||||
|
path = getServerDir() + "/redis.conf" |
||||||
|
return path |
||||||
|
|
||||||
|
|
||||||
|
def getConfTpl(): |
||||||
|
path = getPluginDir() + "/config/redis.conf" |
||||||
|
return path |
||||||
|
|
||||||
|
|
||||||
|
def getInitDTpl(): |
||||||
|
path = getPluginDir() + "/init.d/" + getPluginName() + ".tpl" |
||||||
|
return path |
||||||
|
|
||||||
|
|
||||||
|
def getArgs(): |
||||||
|
args = sys.argv[3:] |
||||||
|
tmp = {} |
||||||
|
args_len = len(args) |
||||||
|
|
||||||
|
if args_len == 1: |
||||||
|
t = args[0].strip('{').strip('}') |
||||||
|
if t.strip() == '': |
||||||
|
tmp = [] |
||||||
|
else: |
||||||
|
t = t.split(':') |
||||||
|
tmp[t[0]] = t[1] |
||||||
|
tmp[t[0]] = t[1] |
||||||
|
elif args_len > 1: |
||||||
|
for i in range(len(args)): |
||||||
|
t = args[i].split(':') |
||||||
|
tmp[t[0]] = t[1] |
||||||
|
return tmp |
||||||
|
|
||||||
|
|
||||||
|
def status(): |
||||||
|
return 'start' |
||||||
|
|
||||||
|
|
||||||
|
def initDreplace(): |
||||||
|
|
||||||
|
file_tpl = getInitDTpl() |
||||||
|
service_path = os.path.dirname(os.getcwd()) |
||||||
|
|
||||||
|
initD_path = getServerDir() + '/init.d' |
||||||
|
if not os.path.exists(initD_path): |
||||||
|
os.mkdir(initD_path) |
||||||
|
file_bin = initD_path + '/' + getPluginName() |
||||||
|
|
||||||
|
# initd replace |
||||||
|
if not os.path.exists(file_bin): |
||||||
|
content = mw.readFile(file_tpl) |
||||||
|
content = content.replace('{$SERVER_PATH}', service_path) |
||||||
|
mw.writeFile(file_bin, content) |
||||||
|
mw.execShell('chmod +x ' + file_bin) |
||||||
|
|
||||||
|
# log |
||||||
|
dataLog = getServerDir() + '/data' |
||||||
|
if not os.path.exists(dataLog): |
||||||
|
mw.execShell('chmod +x ' + file_bin) |
||||||
|
|
||||||
|
# config replace |
||||||
|
dst_conf = getServerDir() + '/redis.conf' |
||||||
|
dst_conf_init = getServerDir() + '/init.pl' |
||||||
|
if not os.path.exists(dst_conf_init): |
||||||
|
conf_content = mw.readFile(getConfTpl()) |
||||||
|
conf_content = conf_content.replace('{$SERVER_PATH}', service_path) |
||||||
|
conf_content = conf_content.replace( |
||||||
|
'{$REDIS_PASS}', mw.getRandomString(10)) |
||||||
|
|
||||||
|
mw.writeFile(dst_conf, conf_content) |
||||||
|
mw.writeFile(dst_conf_init, 'ok') |
||||||
|
|
||||||
|
# systemd |
||||||
|
systemDir = mw.systemdCfgDir() |
||||||
|
systemService = systemDir + '/redis.service' |
||||||
|
systemServiceTpl = getPluginDir() + '/init.d/redis.service.tpl' |
||||||
|
if os.path.exists(systemDir) and not os.path.exists(systemService): |
||||||
|
service_path = mw.getServerDir() |
||||||
|
se_content = mw.readFile(systemServiceTpl) |
||||||
|
se_content = se_content.replace('{$SERVER_PATH}', service_path) |
||||||
|
mw.writeFile(systemService, se_content) |
||||||
|
mw.execShell('systemctl daemon-reload') |
||||||
|
|
||||||
|
return file_bin |
||||||
|
|
||||||
|
|
||||||
|
def dtOp(method): |
||||||
|
file = initDreplace() |
||||||
|
|
||||||
|
return 'ok' |
||||||
|
# data = mw.execShell(file + ' start') |
||||||
|
# if data[1] == '': |
||||||
|
# return 'ok' |
||||||
|
# return 'fail' |
||||||
|
|
||||||
|
|
||||||
|
def start(): |
||||||
|
|
||||||
|
return dtOp('start') |
||||||
|
|
||||||
|
|
||||||
|
def stop(): |
||||||
|
return dtOp('stop') |
||||||
|
|
||||||
|
|
||||||
|
def restart(): |
||||||
|
status = dtOp('restart') |
||||||
|
|
||||||
|
log_file = runLog() |
||||||
|
mw.execShell("echo '' > " + log_file) |
||||||
|
return status |
||||||
|
|
||||||
|
|
||||||
|
def reload(): |
||||||
|
return dtOp('reload') |
||||||
|
|
||||||
|
|
||||||
|
def initdStatus(): |
||||||
|
if mw.isAppleSystem(): |
||||||
|
return "Apple Computer does not support" |
||||||
|
|
||||||
|
shell_cmd = 'systemctl status ' + \ |
||||||
|
getPluginName() + ' | grep loaded | grep "enabled;"' |
||||||
|
data = mw.execShell(shell_cmd) |
||||||
|
if data[0] == '': |
||||||
|
return 'fail' |
||||||
|
return 'ok' |
||||||
|
|
||||||
|
|
||||||
|
def initdInstall(): |
||||||
|
if mw.isAppleSystem(): |
||||||
|
return "Apple Computer does not support" |
||||||
|
|
||||||
|
mw.execShell('systemctl enable ' + getPluginName()) |
||||||
|
return 'ok' |
||||||
|
|
||||||
|
|
||||||
|
def initdUinstall(): |
||||||
|
if mw.isAppleSystem(): |
||||||
|
return "Apple Computer does not support" |
||||||
|
|
||||||
|
mw.execShell('systemctl disable ' + getPluginName()) |
||||||
|
return 'ok' |
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__": |
||||||
|
func = sys.argv[1] |
||||||
|
if func == 'status': |
||||||
|
print(status()) |
||||||
|
elif func == 'start': |
||||||
|
print(start()) |
||||||
|
elif func == 'stop': |
||||||
|
print(stop()) |
||||||
|
elif func == 'restart': |
||||||
|
print(restart()) |
||||||
|
elif func == 'reload': |
||||||
|
print(reload()) |
||||||
|
elif func == 'initd_status': |
||||||
|
print(initdStatus()) |
||||||
|
elif func == 'initd_install': |
||||||
|
print(initdInstall()) |
||||||
|
elif func == 'initd_uninstall': |
||||||
|
print(initdUinstall()) |
||||||
|
elif func == 'run_info': |
||||||
|
print(runInfo()) |
||||||
|
elif func == 'conf': |
||||||
|
print(getConf()) |
||||||
|
elif func == 'run_log': |
||||||
|
print(runLog()) |
||||||
|
else: |
||||||
|
print('error') |
@ -0,0 +1,16 @@ |
|||||||
|
{ |
||||||
|
"sort": 7, |
||||||
|
"ps": "专业使用,动态追踪调试程序![<span style='color:red;'>潜龙勿用</span>]", |
||||||
|
"name": "dynamic-tracking", |
||||||
|
"title": "动态追踪", |
||||||
|
"shell": "install.sh", |
||||||
|
"versions":["0.1"], |
||||||
|
"tip": "soft", |
||||||
|
"checks": "server/dynamic-tracking", |
||||||
|
"path": "server/dynamic-tracking", |
||||||
|
"display": 1, |
||||||
|
"author": "midoks", |
||||||
|
"date": "2023-08-17", |
||||||
|
"type": 0, |
||||||
|
"pid": "4" |
||||||
|
} |
@ -0,0 +1,50 @@ |
|||||||
|
#!/bin/bash |
||||||
|
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin |
||||||
|
export PATH |
||||||
|
|
||||||
|
curPath=`pwd` |
||||||
|
rootPath=$(dirname "$curPath") |
||||||
|
rootPath=$(dirname "$rootPath") |
||||||
|
serverPath=$(dirname "$rootPath") |
||||||
|
|
||||||
|
# cd /www/server/mdserver-web/plugins/dynamic-tracking && /bin/bash install.sh uninstall 1.0 |
||||||
|
# cd /www/server/mdserver-web/plugins/dynamic-tracking && /bin/bash install.sh install 1.0 |
||||||
|
|
||||||
|
install_tmp=${rootPath}/tmp/mw_install.pl |
||||||
|
VERSION=$2 |
||||||
|
|
||||||
|
if [ -f ${rootPath}/bin/activate ];then |
||||||
|
source ${rootPath}/bin/activate |
||||||
|
fi |
||||||
|
|
||||||
|
Install_App() |
||||||
|
{ |
||||||
|
|
||||||
|
echo '正在安装脚本文件...' > $install_tmp |
||||||
|
mkdir -p $serverPath/source |
||||||
|
mkdir -p $serverPath/dynamic-tracking |
||||||
|
|
||||||
|
|
||||||
|
echo "开发中..." |
||||||
|
|
||||||
|
|
||||||
|
echo "${VERSION}" > $serverPath/dynamic-tracking/version.pl |
||||||
|
echo '安装完成' > $install_tmp |
||||||
|
|
||||||
|
cd ${rootPath} && python3 ${rootPath}/plugins/dynamic-tracking/index.py start |
||||||
|
# cd ${rootPath} && python3 ${rootPath}/plugins/dynamic-tracking/index.py initd_install |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
Uninstall_Docker() |
||||||
|
{ |
||||||
|
rm -rf $serverPath/dynamic-tracking |
||||||
|
echo "Uninstall_App" > $install_tmp |
||||||
|
} |
||||||
|
|
||||||
|
action=$1 |
||||||
|
if [ "${1}" == 'install' ];then |
||||||
|
Install_App |
||||||
|
else |
||||||
|
Uninstall_App |
||||||
|
fi |
@ -0,0 +1,54 @@ |
|||||||
|
function redisPost(method, version, args,callback){ |
||||||
|
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); |
||||||
|
|
||||||
|
var req_data = {}; |
||||||
|
req_data['name'] = 'dynamic-tracking'; |
||||||
|
req_data['func'] = method; |
||||||
|
req_data['version'] = version; |
||||||
|
|
||||||
|
if (typeof(args) == 'string'){ |
||||||
|
req_data['args'] = JSON.stringify(toArrayObject(args)); |
||||||
|
} else { |
||||||
|
req_data['args'] = JSON.stringify(args); |
||||||
|
} |
||||||
|
|
||||||
|
$.post('/plugins/run', req_data, function(data) { |
||||||
|
layer.close(loadT); |
||||||
|
if (!data.status){ |
||||||
|
//错误展示10S
|
||||||
|
layer.msg(data.msg,{icon:0,time:2000,shade: [10, '#000']}); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
if(typeof(callback) == 'function'){ |
||||||
|
callback(data); |
||||||
|
} |
||||||
|
},'json');
|
||||||
|
} |
||||||
|
|
||||||
|
function redisPostCallbak(method, version, args,callback){ |
||||||
|
var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); |
||||||
|
|
||||||
|
var req_data = {}; |
||||||
|
req_data['name'] = 'dynamic-tracking'; |
||||||
|
req_data['func'] = method; |
||||||
|
args['version'] = version; |
||||||
|
|
||||||
|
if (typeof(args) == 'string'){ |
||||||
|
req_data['args'] = JSON.stringify(toArrayObject(args)); |
||||||
|
} else { |
||||||
|
req_data['args'] = JSON.stringify(args); |
||||||
|
} |
||||||
|
|
||||||
|
$.post('/plugins/callback', req_data, function(data) { |
||||||
|
layer.close(loadT); |
||||||
|
if (!data.status){ |
||||||
|
layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']}); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
if(typeof(callback) == 'function'){ |
||||||
|
callback(data); |
||||||
|
} |
||||||
|
},'json');
|
||||||
|
} |
Loading…
Reference in new issue