diff --git a/.gitignore b/.gitignore index f54343adb..00e6e8afd 100644 --- a/.gitignore +++ b/.gitignore @@ -112,4 +112,3 @@ data/json/index.json *.zip data/*.db data/control.conf -plugins/memcached/init.d/memcached diff --git a/plugins/memcached/index.html b/plugins/memcached/index.html index 1919a969a..61acc3dca 100755 --- a/plugins/memcached/index.html +++ b/plugins/memcached/index.html @@ -2,6 +2,7 @@

服务

+

自启动

配置修改

负载状态

性能调整

diff --git a/plugins/memcached/index.py b/plugins/memcached/index.py index 6725f8923..ffbf567dc 100755 --- a/plugins/memcached/index.py +++ b/plugins/memcached/index.py @@ -8,6 +8,8 @@ import time sys.path.append(os.getcwd() + "/class/core") import public +app_debug = True + def getAppName(): return 'memcached' @@ -21,6 +23,12 @@ def getServerDir(): return public.getServerDir() + '/' + getAppName() +def getInitDFile(): + if app_debug: + return '/tmp/' + getAppName() + return '/etc/init.d/' + getAppName() + + def getConf(): path = getPluginDir() + "/init.d/memcached.tpl" return path @@ -37,7 +45,7 @@ def getArgs(): def status(): data = public.execShell( - "ps -ef|grep memcached |grep -v grep | grep -v python | awk '{print $2}'") + "ps -ef|grep " + getAppName() + " |grep -v grep | grep -v python | awk '{print $2}'") if data[0] == '': return 'stop' return 'start' @@ -155,15 +163,43 @@ def saveConf(): return 'fail' +def initdStatus(): + if not app_debug: + os_name = public.getOs() + if os_name == 'darwin': + return "Apple Computer does not support" + initd_bin = getInitDFile() + if os.path.exists(initd_bin): + return 'ok' + return 'fail' + + +def initdInstall(): + import shutil + if not app_debug: + os_name = public.getOs() + if os_name == 'darwin': + return "Apple Computer does not support" + + mem_bin = initDreplace() + initd_bin = getInitDFile() + shutil.copyfile(mem_bin, initd_bin) + public.execShell('chmod +x ' + initd_bin) + return 'ok' + + +def initdUinstall(): + if not app_debug: + os_name = public.getOs() + if os_name == 'darwin': + return "Apple Computer does not support" + initd_bin = getInitDFile() + os.remove(initd_bin) + return 'ok' + if __name__ == "__main__": func = sys.argv[1] - if func == 'run_info': - print runInfo() - elif func == 'conf': - print getConf() - elif func == 'save_conf': - print saveConf() - elif func == 'status': + if func == 'status': print status() elif func == 'start': print start() @@ -173,5 +209,17 @@ if __name__ == "__main__": 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 == 'save_conf': + print saveConf() else: print 'fail' diff --git a/static/app/public.js b/static/app/public.js index 19304d45f..0922e029a 100755 --- a/static/app/public.js +++ b/static/app/public.js @@ -1623,4 +1623,58 @@ function pluginConfigSave(fileName) { }); },'json'); } + + +function pluginInitD(_name){ + $.post('/plugins/run', {name:_name, func:'initd_status'}, function(data) { + if(!data.status || (data.data!='ok' && data.data!='fail') ){ + layer.msg(data.data,{icon:0,time:3000,shade: [0.3, '#000']}); + return; + } + if (data.data == 'ok'){ + pluginSetInitD(_name, true); + } else { + pluginSetInitD(_name, false); + } + },'json'); +} + +function pluginSetInitD(_name, status){ + var serviceCon ='

当前状态:'+(status ? '已加载' : '未加载' )+ + '

\ + \ +
'; + $(".soft-man-con").html(serviceCon); +} + +function pluginOpInitD(a, b) { + var c = "name=" + a + "&func=" + b; + var d = ""; + switch(b) { + case "initd_install":d = '加载';break; + case "initd_uninstall":d = '卸载';break; + } + layer.confirm( msgTpl('您真的要{1}{2}服务吗?', [d,a]), {icon:3,closeBtn: 2}, function() { + var e = layer.msg(msgTpl('正在{1}{2}服务,请稍候...',[d,a]), {icon: 16,time: 0}); + $.post("/plugins/run", c, function(g) { + layer.close(e); + var f = g.data == 'ok' ? msgTpl('{1}服务已{2}',[a,d]) : msgTpl('{1}服务{2}失败!',[a,d]); + layer.msg(f, {icon: g.data == 'ok' ? 1 : 2}); + + if ( b == 'initd_install' && g.data == 'ok' ) { + pluginSetInitD(a, true); + }else{ + pluginSetInitD(a, false); + } + 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: 0}); + }); + }) +} /*** 其中功能,针对插件通过库使用 end ***/ \ No newline at end of file