diff --git a/plugins/redis/index.py b/plugins/redis/index.py index 4c558c055..e954d4d0f 100755 --- a/plugins/redis/index.py +++ b/plugins/redis/index.py @@ -10,8 +10,42 @@ import public def status(): + data = public.execShell( + "ps -ef|grep redis |grep -v grep | grep -v python | awk '{print $2}'") + if data[0] == '': + return 'stop' + return 'start' - cmd = os.path.dirname(os.getcwd()) + "/redis/bin/redis-cli info" + +def start(): + path = os.path.dirname(os.getcwd()) + cmd = path + "/redis/bin/redis-server" + cmd = cmd + " " + path + "/redis/redis.conf" + data = public.execShell(cmd) + if data[0] == '': + return 'ok' + return 'fail' + + +def stop(): + data = public.execShell( + "ps -ef|grep redis |grep -v grep |grep -v python |awk '{print $2}' | xargs kill -9") + if data[0] == '': + return 'ok' + return 'fail' + + +def restart(): + return 'ok' + + +def reload(): + return 'ok' + + +def runInfo(): + path = os.path.dirname(os.getcwd()) + cmd = path + "/redis/bin/redis-cli info" data = public.execShell(cmd)[0] res = [ 'tcp_port', @@ -44,10 +78,19 @@ def getConf(): path = os.path.dirname(os.getcwd()) + "/redis/redis.conf" return path - if __name__ == "__main__": func = sys.argv[1] - if func == 'status': - print status() + if func == 'run_info': + print runInfo() elif func == 'conf': print getConf() + elif func == 'status': + print status() + elif func == 'start': + print start() + elif func == 'stop': + print stop() + elif func == 'restart': + print restart() + elif func == 'reload': + print reload() diff --git a/plugins/redis/js/redis.js b/plugins/redis/js/redis.js index 00e6b72d0..d90e983ac 100755 --- a/plugins/redis/js/redis.js +++ b/plugins/redis/js/redis.js @@ -1,24 +1,83 @@ +function redisOp(a, b) { + var c = "name=" + a + "&func=" + b; + var d = ""; - + switch(b) { + case "stop": + d = '停止'; + break; + case "start": + d = '启动'; + break; + case "restart": + d = '重启'; + break; + case "reload": + d = '重载'; + break + } + layer.confirm( '您真的要{1}{2}服务吗?'.replace('{1}', d).replace('{2}', a), {icon:3,closeBtn: 2}, function() { + var e = layer.msg('正在{1}{2}服务,请稍候...'.replace('{1}', d).replace('{2}', a), {icon: 16,time: 0}); + $.post("/plugins/run", c, function(g) { + layer.close(e); + + var f = g.data == 'ok' ? '{1}服务已{2}'.replace('{1}', a).replace('{2}', d):'{1}服务{2}失败!'.replace('{1}', a).replace('{2}', d); + layer.msg(f, {icon: g.data == 'ok' ? 1 : 2}); + + if(b != "reload" && g.data == 'ok') { + if (b == 'start') { + setRedisService('redis', true); + } else if (b=='stop'){ + setRedisService('redis', false); + } else { + } + } + if(g.data != 'ok') { + layer.msg(g.data, {icon: 2,time: 0,shade: 0.3,shadeClose: true}); + } + },'json').error(function() { + layer.close(e); + layer.msg('操作成功!', {icon: 1}); + }); + }) +} //服务 -function redisService(){ - var status = false; - var name = 'redis'; - +function setRedisService(name, status){ var serviceCon ='

当前状态:'+(status ? '开启' : '关闭' )+ '

\ - \ - \ - \ + \ + \ + \
'; $(".soft-man-con").html(serviceCon); } -//配置修改 + +//服务 +function redisService(){ + + $.post('/plugins/run', {name:'redis', func:'status'}, function(data) { + console.log(data); + if(!data.status){ + layer.msg(data.msg,{icon:0,time:3000,shade: [0.3, '#000']}); + return; + } + if (data.data == 'start'){ + setRedisService('redis', true); + } else { + setRedisService('redis', false); + } + },'json'); +} + +redisService(); + + +//配置修改 --- start function redisConfig(type){ var con = '

提示:Ctrl+F 搜索关键字,Ctrl+G 查找下一个,Ctrl+S 保存,Ctrl+Shift+R 查找替换!

\ @@ -31,14 +90,26 @@ function redisConfig(type){ var loadT = layer.msg('配置文件路径获取中...',{icon:16,time:0,shade: [0.3, '#000']}); $.post('/plugins/run', {name:'redis', func:'conf'},function (data) { layer.close(loadT); + var loadT2 = layer.msg('文件内容获取中...',{icon:16,time:0,shade: [0.3, '#000']}); var fileName = data.data; $.post('/files/get_body', 'path=' + fileName, function(rdata) { layer.close(loadT2); + if (!rdata.status){ + layer.msg(rdata.msg,{icon:0,time:2000,shade: [0.3, '#000']}); + return; + } $("#textBody").empty().text(rdata.data.data); $(".CodeMirror").remove(); var editor = CodeMirror.fromTextArea(document.getElementById("textBody"), { - extraKeys: {"Ctrl-Space": "autocomplete"}, + extraKeys: { + "Ctrl-Space": "autocomplete", + "Ctrl-F": "findPersistent", + "Ctrl-H": "replaceAll", + "Ctrl-S": function() { + redisConfSafe(fileName); + } + }, lineNumbers: true, matchBrackets:true, }); @@ -67,14 +138,15 @@ function redisConfSafe(fileName) { }); },'json'); } +//配置修改 --- end - -//redis负载状态 +//redis负载状态 start function redisStatus() { var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); - $.post('/plugins/run', {name:'redis', func:'status'}, function(data) { + $.post('/plugins/run', {name:'redis', func:'run_info'}, function(data) { layer.close(loadT); if (!data.status){ + layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']}); return; } @@ -103,5 +175,4 @@ function redisStatus() { $(".soft-man-con").html(Con); },'json'); } - -redisService(); \ No newline at end of file +//redis负载状态 end \ No newline at end of file diff --git a/route/plugins.py b/route/plugins.py index 4c4a3e95f..305ea9dc6 100644 --- a/route/plugins.py +++ b/route/plugins.py @@ -138,6 +138,7 @@ def run(): else: py = py + '/' + script + '.py' + ' ' + func + ' ' + args + print py data = public.execShell(py) if data[1].strip() == '': diff --git a/static/js/public.js b/static/js/public.js index c38ff4399..8afea55e9 100755 --- a/static/js/public.js +++ b/static/js/public.js @@ -359,6 +359,7 @@ function openPath(a) { window.location.href = "/files" } + function OnlineEditFile(k, f) { if(k != 0) { var l = $("#PathPlace input").val();