From 5b73b73f16b5e5d4593ae7b0b2d984b71d48307b Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Fri, 7 Dec 2018 14:18:30 +0800 Subject: [PATCH] update --- class/core/public.py | 8 +++++ plugins/memcached/index.py | 67 +++++++++++++++++++++++++++++--------- 2 files changed, 59 insertions(+), 16 deletions(-) diff --git a/class/core/public.py b/class/core/public.py index 8aa6ad7a4..de88ac5b6 100755 --- a/class/core/public.py +++ b/class/core/public.py @@ -46,6 +46,14 @@ def getRootDir(): return os.path.dirname(os.path.dirname(getRunDir())) +def getPluginDir(): + return getRunDir() + '/plugins' + + +def getServerDir(): + return getRootDir() + '/server' + + def getOs(): os = execShell('uname') return os[0].lower().strip() diff --git a/plugins/memcached/index.py b/plugins/memcached/index.py index c5883f7ff..6725f8923 100755 --- a/plugins/memcached/index.py +++ b/plugins/memcached/index.py @@ -9,6 +9,32 @@ sys.path.append(os.getcwd() + "/class/core") import public +def getAppName(): + return 'memcached' + + +def getPluginDir(): + return public.getPluginDir() + '/' + getAppName() + + +def getServerDir(): + return public.getServerDir() + '/' + getAppName() + + +def getConf(): + path = getPluginDir() + "/init.d/memcached.tpl" + return path + + +def getArgs(): + args = sys.argv[2:] + tmp = {} + for i in range(len(args)): + t = args[i].split(':') + tmp[t[0]] = t[1] + return tmp + + def status(): data = public.execShell( "ps -ef|grep memcached |grep -v grep | grep -v python | awk '{print $2}'") @@ -20,14 +46,17 @@ def status(): def initDreplace(): file_tpl = getConf() - file_bin = os.getcwd() + '/plugins/memcached/init.d/memcached' + service_path = os.path.dirname(os.getcwd()) - if os.path.exists(file_bin): - return file_bin + initD_path = getServerDir() + '/init.d' + if not os.path.exists(initD_path): + os.mkdir(initD_path) + file_bin = initD_path + '/memcached' - content = public.readFile(file_tpl) + # if os.path.exists(file_bin): + # return file_bin - service_path = os.path.dirname(os.getcwd()) + content = public.readFile(file_tpl) content = content.replace('{$SERVER_PATH}', service_path) public.writeFile(file_bin, content) @@ -106,22 +135,28 @@ def runInfo(): return public.getJson({}) -def getConf(): - path = os.getcwd() + "/plugins/memcached/init.d/memcached.tpl" - return path - - def saveConf(): - args = sys.argv[2] - if args == '': - return 'fail' - - print args + # 设置memcached缓存大小 + import re + confFile = getConf() + try: + args = getArgs() + content = public.readFile(confFile) + content = re.sub('IP=.+', 'IP=' + args['ip'], content) + content = re.sub('PORT=\d+', 'PORT=' + args['port'], content) + content = re.sub('MAXCONN=\d+', 'MAXCONN=' + args['maxconn'], content) + content = re.sub('CACHESIZE=\d+', 'CACHESIZE=' + + args['cachesize'], content) + public.writeFile(confFile, content) + reload() + return 'ok' + except Exception as e: + pass + return 'fail' if __name__ == "__main__": func = sys.argv[1] - print sys.argv if func == 'run_info': print runInfo() elif func == 'conf':